How to display only taxonomies of custom post type in a page?

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?

Topic taxonomy custom-taxonomy custom-post-types Wordpress

Category Web


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 );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.