Question

I've created a page with list of custom terms: enter image description here

Under each Term, i need to show every posts with post_type = 'courses'e taxnonomy = 'courses_category'

What will be the query to display those records?

Thanks

Was it helpful?

Solution

You will need to use this code:

$the_query = new WP_Query( array(
'post_type' => 'courses',
'tax_query' => array(
    array (
        'taxonomy' => 'courses_category',
        'field' => 'slug',
        'terms' => 'yourterm'
    )
),

    ) );

while ( $the_query->have_posts() ) :
    $the_query->the_post();
    // Show Posts ...
endwhile;

You can convert this in shortcode and just append it on your page trough your wordpress content editor or just insert this where you want to show your posts.

Check Codex or this link

OTHER TIPS

Try this:

$query = new WP_Query(array(
    'post_type'=>'courses',
    'nopaging'=>true,
    'tax_query'=> array(
        array('taxonomy'=>'courses_category',
        'field'=>'slug',
        'terms'=>'recursos-humanos'//replace this with the term slugs
        )
    )
));

I would probably use three queries for the three terms you have above (changing the 'terms' value with the slug of the taxonomy term. You could get fancy and link all three terms together with a single query ordered by post type.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top