Support » Themes and Templates » Retrieving Posts from Two Taxonomies and Post Types

  • I’ve pulled my hair out on this for about 2 days, googled everything I can think of.

    I have a custom taxonomy called ‘tkb_recipe’:

    # Add post type:  recipe
    	register_post_type( 'tkb_recipe',
    		array(
    			'labels' => array(
    				'name' => __( 'Recipes' ),
    				'singular_name' => __( 'Recipe' )
    			),
    			'public' => true,
    			'has_archive' => true,
    			'rewrite' => array('slug' => 'recipes'),
    			'supports' => array(
    				'title',
    				'comments',
    				'custom-fields',
    				'editor',
    				'revisions',
    				'thumbnail'
    			),
    			'taxonomies' => array(
    				'recipe_cat',
    				'post_tag'
    			)
    		)
    	);

    I am trying to query posts from two different recipe categories to be displayed on the same page, in an AND fashion, so only when it is in both categories is it shown:

    $args = array(
        'post_type'=> 'tkb_recipe',
    		'recipe_cat' => $_GET['cat1'], $_GET['cat2']
        );
    $loop = new WP_Query( $args );

    The problem is that this is not working at all. I either get an OR equivalent or something else no matter what I’ve tried. Any ideas here?

    One category is a parent category called ‘appetizers’ (slug) and the other is ‘gluten-free’, which is a child of the category ‘variations’. I think the issue may be with the fact that I am trying to query both a parent and a child category but I don’t know how to overcome that.

    Any help I’d be eternally grateful, thank you WordPress community!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Retrieving Posts from Two Taxonomies and Post Types’ is closed to new replies.