Support

Account

Home Forums General Issues Get 3 posts from a Custom Post Type of a specific Category?

Helping

Get 3 posts from a Custom Post Type of a specific Category?

  • I need to show three images for each Category of a Brand for all Brands, separated into boxes by Custom Post Type and Category.

    
      --------------------    --------------------    --------------------
         img1 img2 img3         img1 img2 img3           img1 img2 img3
      
      CAT_1 by CPT BRAND 1    CAT_2 by CPT BRAND 1    CAT_3 by CPT BRAND 1
      --------------------    --------------------    -------------------- 
    
                 --------------------    --------------------
                    img1 img2 img3         img1 img2 img3
      
                 CAT_1 by CPT BRAND 2    CAT_2 by CPT BRAND 2
                 --------------------    --------------------
    
      --------------------    --------------------    --------------------
        img1 img2 img3         img1 img2 img3           img1 img2 img3
      
      CAT_1 by CPT BRAND 3    CAT_2 by CPT BRAND 3    CAT_3 by CPT BRAND 3
      --------------------    --------------------    --------------------
    
      ...
    

    img(n) is a Custom Post Type of Jewellery, CPT is the Custom Post Type of Brand, CAT is a Category that a Brand has.

    What would the the most efficient way to get this from the DB?

    1. Get all Brands from the CPT
    2. Iterate all Brands and get all Categories for that Brand ?
    3. Get 3 posts (images) for that category of that Brand … ?

    Hope the explanation makes sense of what I’m trying to achieve.

  • Basically yes, I’m guessing that jewellery is related to brand by a post object field. But your list of steps looks correct to me.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Get 3 posts from a Custom Post Type of a specific Category?’ is closed to new replies.