admin管理员组文章数量:1024615
I have a custom post called "rock" and taxonomy "genres" i need to filter the posts with tag or something like
post_type > taxonomy > taxonomy_tag (tagsss)
I can not find a solution :(
i have register a new tag taxonomies in the fuctions (like tag) (is not whether it is a good choice)
add_action( 'init', 'create_tag_taxonomiess', 0 );
function create_tag_taxonomiess()
{
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Tags' ),
'popular_items' => __( 'Popular Tags' ),
'all_items' => __( 'All Tags' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Tag' ),
'update_item' => __( 'Update Tag' ),
'add_new_item' => __( 'Add New Tag' ),
'new_item_name' => __( 'New Tag Name' ),
'separate_items_with_commas' => __( 'Separate tags with commas' ),
'add_or_remove_items' => __( 'Add or remove tags' ),
'choose_from_most_used' => __( 'Choose from the most used tags' ),
'menu_name' => __( 'Tags' ),
);
register_taxonomy('tagsss','rock',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'tag' ),
));
}
my loop in taxonomy-genres-events.php
<?php $args = array( 'post_type' => 'rock','taxonomy' => 'genres','tagsss' =>'concerts', 'orderby' => 'menu-order' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $rock; ?>
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php endwhile;?>
EDIT:
I have found the solution by myself
<?php
$args = array(
'tax_query' => array(
array(
'posts_per_page' => 5,
'order' => 'DESC',
'taxonomy' => 'tagsss',
'field' => 'slug',
'terms' => 'concerts',
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();?>
I have a custom post called "rock" and taxonomy "genres" i need to filter the posts with tag or something like
post_type > taxonomy > taxonomy_tag (tagsss)
I can not find a solution :(
i have register a new tag taxonomies in the fuctions (like tag) (is not whether it is a good choice)
add_action( 'init', 'create_tag_taxonomiess', 0 );
function create_tag_taxonomiess()
{
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Tags' ),
'popular_items' => __( 'Popular Tags' ),
'all_items' => __( 'All Tags' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Tag' ),
'update_item' => __( 'Update Tag' ),
'add_new_item' => __( 'Add New Tag' ),
'new_item_name' => __( 'New Tag Name' ),
'separate_items_with_commas' => __( 'Separate tags with commas' ),
'add_or_remove_items' => __( 'Add or remove tags' ),
'choose_from_most_used' => __( 'Choose from the most used tags' ),
'menu_name' => __( 'Tags' ),
);
register_taxonomy('tagsss','rock',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'tag' ),
));
}
my loop in taxonomy-genres-events.php
<?php $args = array( 'post_type' => 'rock','taxonomy' => 'genres','tagsss' =>'concerts', 'orderby' => 'menu-order' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $rock; ?>
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php endwhile;?>
EDIT:
I have found the solution by myself
<?php
$args = array(
'tax_query' => array(
array(
'posts_per_page' => 5,
'order' => 'DESC',
'taxonomy' => 'tagsss',
'field' => 'slug',
'terms' => 'concerts',
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();?>
Share
Improve this question
edited Dec 9, 2014 at 22:18
user3766356
asked Dec 9, 2014 at 21:03
user3766356user3766356
131 silver badge6 bronze badges
1 Answer
Reset to default 0You cannot natively query broadly by taxonomy, only by terms
If you study through Taxonomy Parameters in Codex it is now pretty easy to construct conditions for multiple sets of terms required.
Still it's not completely flexible, I won't know easy way to do things like “having any term in some taxonomy” on top of my head.
I have a custom post called "rock" and taxonomy "genres" i need to filter the posts with tag or something like
post_type > taxonomy > taxonomy_tag (tagsss)
I can not find a solution :(
i have register a new tag taxonomies in the fuctions (like tag) (is not whether it is a good choice)
add_action( 'init', 'create_tag_taxonomiess', 0 );
function create_tag_taxonomiess()
{
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Tags' ),
'popular_items' => __( 'Popular Tags' ),
'all_items' => __( 'All Tags' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Tag' ),
'update_item' => __( 'Update Tag' ),
'add_new_item' => __( 'Add New Tag' ),
'new_item_name' => __( 'New Tag Name' ),
'separate_items_with_commas' => __( 'Separate tags with commas' ),
'add_or_remove_items' => __( 'Add or remove tags' ),
'choose_from_most_used' => __( 'Choose from the most used tags' ),
'menu_name' => __( 'Tags' ),
);
register_taxonomy('tagsss','rock',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'tag' ),
));
}
my loop in taxonomy-genres-events.php
<?php $args = array( 'post_type' => 'rock','taxonomy' => 'genres','tagsss' =>'concerts', 'orderby' => 'menu-order' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $rock; ?>
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php endwhile;?>
EDIT:
I have found the solution by myself
<?php
$args = array(
'tax_query' => array(
array(
'posts_per_page' => 5,
'order' => 'DESC',
'taxonomy' => 'tagsss',
'field' => 'slug',
'terms' => 'concerts',
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();?>
I have a custom post called "rock" and taxonomy "genres" i need to filter the posts with tag or something like
post_type > taxonomy > taxonomy_tag (tagsss)
I can not find a solution :(
i have register a new tag taxonomies in the fuctions (like tag) (is not whether it is a good choice)
add_action( 'init', 'create_tag_taxonomiess', 0 );
function create_tag_taxonomiess()
{
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Tags' ),
'popular_items' => __( 'Popular Tags' ),
'all_items' => __( 'All Tags' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Tag' ),
'update_item' => __( 'Update Tag' ),
'add_new_item' => __( 'Add New Tag' ),
'new_item_name' => __( 'New Tag Name' ),
'separate_items_with_commas' => __( 'Separate tags with commas' ),
'add_or_remove_items' => __( 'Add or remove tags' ),
'choose_from_most_used' => __( 'Choose from the most used tags' ),
'menu_name' => __( 'Tags' ),
);
register_taxonomy('tagsss','rock',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'tag' ),
));
}
my loop in taxonomy-genres-events.php
<?php $args = array( 'post_type' => 'rock','taxonomy' => 'genres','tagsss' =>'concerts', 'orderby' => 'menu-order' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $rock; ?>
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php endwhile;?>
EDIT:
I have found the solution by myself
<?php
$args = array(
'tax_query' => array(
array(
'posts_per_page' => 5,
'order' => 'DESC',
'taxonomy' => 'tagsss',
'field' => 'slug',
'terms' => 'concerts',
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();?>
Share
Improve this question
edited Dec 9, 2014 at 22:18
user3766356
asked Dec 9, 2014 at 21:03
user3766356user3766356
131 silver badge6 bronze badges
1 Answer
Reset to default 0You cannot natively query broadly by taxonomy, only by terms
If you study through Taxonomy Parameters in Codex it is now pretty easy to construct conditions for multiple sets of terms required.
Still it's not completely flexible, I won't know easy way to do things like “having any term in some taxonomy” on top of my head.
本文标签: Loop multiple taxonomy in custom post
版权声明:本文标题:Loop multiple taxonomy in custom post 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745603540a2158597.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论