Show post types linked to a taxonomy
How to return all post_type bound to a taxonomy?
1
Author: Flávia Amaral, 2014-02-25
3 answers
Quick way:
Assuming your taxonomy is "people" and the person you want to fetch is "bob":
$args = array(
'post_type' => 'post',
'pessoas' => 'bob'
);
$query = new WP_Query( $args );
Another way to do the same thing...
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'pessoas',
'field' => 'slug',
'terms' => 'bob'
)
)
);
$query = new WP_Query( $args );
Is also valid for searching in more than one taxonomy:
$args = array(
'post_type' => 'post',
'pessoas' => 'bob',
'language' => 'english'
);
$query = new WP_Query( $args );
Is all in Codex
2
Author: Bruno Rodrigues, 2014-02-26 04:19:05
Just use the following code and change the vari 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();
}
1
Author: Leandro Costa, 2014-02-25 21:30:37
The question has little information, but from what I understand you need to list posts (regardless of the type, whether post, page or other you created), so in the 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
);
?>
0
Author: Rone Clay Brasil, 2014-02-25 21:17:36