0

What I want to do is display posts that share a taxonomy on a page with that taxonomies name.

For example, a page named "PHP" would display all the of posts with the custom taxonomy "language" set to "PHP".

What I have so far..

$secondary_loop = new WP_Query(array( 'tax_query' => array(
            array(
                'taxonomy' => 'language',
                'terms'    => get_the_title()
            ) ), 
            'posts_per_page' => 5 ));

        while ( $secondary_loop->have_posts() ) : $secondary_loop->the_post();
            the_title();
            the_date('m/d/y');
            the_excerpt();
        endwhile;
        wp_reset_postdata();

As of right now, this does not display any of the posts, but does give me..

object(WP_Query)#248 (46) { ["query"]=> array(2) { ["tax_query"]=> array(1) { [0]=> array(2) { ["taxonomy"]=> string(10) "language" ["terms"]=> string(22) "PHP" } } ...

When I var_dump($secondary_loop). So I know it retrieves the title, which matches the taxonmy value, but it fails to display it.

1 Answer 1

1

If you don't define the field in the array then it defaults to ID. Your options are term_id, name and slug: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

'tax_query' => array(
    array(
        'taxonomy' => 'language',
        'field'    => 'name',
        'terms'    => get_the_title()
    )
)
1
  • I've added the 'field' key, but it still doesn't display any posts on my page.
    – Chris
    Feb 24, 2015 at 7:38

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.