WordPress.org

Ready to get started?Download WordPress

Forums

Retrieving Posts from Two Taxonomies and Post Types (2 posts)

  1. zcode7
    Member
    Posted 2 years ago #

    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!

  2. zcode7
    Member
    Posted 2 years ago #

    Just a little bump here. Any ideas?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.