Вопрос

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

Это было полезно?

Решение

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

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с wordpress.stackexchange
scroll top