0

I have created recipe as a custom post and types as a taxonomy. In that taxonomy I have created vegetables and fruits as fields and I have 5 posts in each fields, but I need to display only vegetables and fruits in the page?

The below Query is what I currently use. It displays all posts.

<?php
    $mypost = array( 'post_type' => 'recipe', );
    $loop = new WP_Query( array( 'post_type' => 'recipe', 'posts_per_page' => 9 ) );
?>

Can anyone help me?

1
  • Can you fix your code? It was mangled. Do you just want to list the taxonomy terms? Or the posts in those terms? Jul 19, 2013 at 10:06

1 Answer 1

0

You can use a taxonomy query, like this:

$args = array(
        'post_type' => 'recipe',
        'tax_query' => array(
            array(
                'taxonomy' => 'types',
                'field' => 'slug',
                'terms' => array( 'vegetables', 'fruit' )
                 )
        )
);
$query = new WP_Query( $args );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.