Show post_types linked to a taxonomy

1

How to return all post_type linked to a taxonomy?

    
asked by anonymous 25.02.2014 / 19:32

3 answers

2

Quick form:

Assuming your taxonomy is "people" and the person you want to search for is "bob":

$args = array(
'post_type' => 'post',
'pessoas' => 'bob'
);
$query = new WP_Query( $args );

Another way of doing the same thing ...

$args = array(
'post_type' => 'post',
'tax_query' => array(
    array(
        'taxonomy' => 'pessoas',
        'field' => 'slug',
        'terms' => 'bob'
    )
)
);
$query = new WP_Query( $args );

Also applicable to search in more than one taxonomy:

$args = array( 
    'post_type' => 'post',
    'pessoas' => 'bob',
    'language' => 'english'
);
$query = new WP_Query( $args );

It's all in the Codex

    
26.02.2014 / 05:19
1

Only use the following code and change the $ type variable to the name of your taxonomy.

            $type = 'nomedataxonomia';
            $args=array(
              'post_type' => $type,
              'post_status' => 'publish',
              'posts_per_page' => -1,
            );


                $my_query = new WP_Query($args);
                while ($my_query->have_posts()){
                      $my_query->the_post();
                }
    
25.02.2014 / 22:30
0

The question has little information, but from what I understand you need to list posts (regardless of the type, post, page or other you have created), then Codex we have the following suggestion:

<?php
$args = array(
'posts_per_page'   => 5,
'offset'           => 0,
'category'         => '',
'orderby'          => 'post_date',
'order'            => 'DESC',
'include'          => '',
'exclude'          => '',
'meta_key'         => '',
'meta_value'       => '',
'post_type'        => 'post',
'post_mime_type'   => '',
'post_parent'      => '',
'post_status'      => 'publish',
'suppress_filters' => true
 );
 ?>
    
25.02.2014 / 21:50