0

I've got a custom post type called "listing" a custom taxonomy called "listing_tags". I'd like to display the listing post type posts that have a listing_tag called "basic". Is this possible? I thought something like the following would get me started, but no luck at all.

$custom_terms = get_terms('listings_tags');

foreach($custom_terms as $custom_term) {
    wp_reset_query();
    $args = array('post_type' => 'listing',
        'tax_query' => array(
            array(
                'taxonomy' => 'listings_tags',
                'field' => 'slug',
                'terms' => $custom_term->basic,
            ),
        ),
     );

     $loop = new WP_Query($args);
     if($loop->have_posts()) {
        echo '<h2>'.$custom_term->name.'</h2>';

        while($loop->have_posts()) : $loop->the_post();
            echo '<a href="'.get_permalink().'">'.get_the_title().'</a>';
        endwhile;
     }
}

1 Answer 1

2

The problem is in your tax_query terms parameter.

Try:

'tax_query' => array(
        array(
            'taxonomy' => 'listings_tags',
            'field' => 'slug',
            'terms' => $custom_term->slug,
        ),
 ),

And if you want posts from just basic, there's no need for getting terms and loopin through. All you can do is WP_Query with tax_query terms parameter as 'basic'.

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.