Question

I'm having a little trouble with a custom taxonomy template. I inherited a site that was developed by someone else and they use "Types" plugin to add some custom taxonomies.

Goal:

to have an archive template that shows only posts with a certain taxonomy term in it at example-domain.com/people/harrison-ford

Problem:

This code is bringing in posts that do not have the taxonomy selected.

Here's my full code:

<?php
$year = get_post_meta($post->ID, 'year', true);
$post_type = 'post';
$tax = 'people';
$tax_terms = get_terms( $tax );
if ($tax_terms) {
    $args = array(
        'post_type' => $post_type,
        'people' => 'harrison-ford',
        "$tax" => $tax_term->slug,
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'caller_get_posts'=> 1,
            'orderby' => 'date',
            'order' => DESC
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) : ?>
        <h2 class="wwNews"><?php echo $tax_term->name; ?> News</h2>
        <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>

<-- display stuff -->

        <?php endwhile; // end of loop ?>
    <?php endif; // if have_posts()
    wp_reset_query();

}
?>
Was it helpful?

Solution

What are you expecting here? "$tax" is going to to be 'people' =>, which is going to overwrite 'harrison-ford' to the value of $tax_term->slug.

'people' => 'harrison-ford',
"$tax" => $tax_term->slug,

Furthermore, I don't know of any custom argument called people, I'm pretty sure that you want tax_query:

'tax_query' => array(
    'taxonomy' => 'people',
    'terms' => array('harrison-ford', $tax_term->slug)
)

Which will give you the results of all people matching harrison-ford and the value of $tax_term->slug within the taxonomy of people

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top