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 '13 at 10:06
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, privacy policy and cookie policy

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