0

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();?> 

1 Answer 1

0

You 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.