0

I would like to display in the single page sidebar all the posts related with the Current Custom Taxonomy (taxonomy name: authors) and also filter the list of posts by a tag or category.

I found this on wordpress codex. With this code I can see a list of posts filter by Tag 'tag_slug'.

    $args = array(
        'post_type' => 'post',
        'tag' => 'tag_slug',
        'tax_query' => array(
            array(
                'taxonomy' => 'authors',
                'field' => 'slug',
                'terms' => 'elenap',
            )  
        ),
        'orderby' => 'date',
        'order'   => 'DESC',
    );
    $query = new WP_Query( $args );

// The Loop
            if ( $query->have_posts() ) {
            echo '<ul>';
            while ( $query->have_posts() ) {
                $query->the_post();
                echo '<li>' . get_the_title() . '</li>';
            }
            echo '</ul>';
            } else {
                // no posts found   
            }
        /* Restore original Post Data */
        wp_reset_postdata(); ?>

How can I get the current taxonomy? Like:

'terms' => $currenttaxonomy,
11
  • Your taxonomy name is not people but authors and you have to put the term name in the terms field
    – Laxmana
    Jul 16, 2015 at 16:09
  • Yes, I know ;) I just pasted the code from wordpress codex. Now I edited the code above.
    – Elena
    Jul 16, 2015 at 16:25
  • Please use the site search for related posts Jul 16, 2015 at 16:30
  • Would you mind posting also the code you run the query?
    – Laxmana
    Jul 16, 2015 at 16:34
  • @Laxmana, I edited the code with the loop after WP_Query.
    – Elena
    Jul 16, 2015 at 23:03

0

Your Answer

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

Browse other questions tagged or ask your own question.