[Resolved] WP_Query, using a variable in tax_query terms
I have a wp_query that grabs a custom field, this custom field is a term id for a category of a custom post type’s categories called classes. If only one type is selected then this code works fine;
<?php $listing_cat = get_post_meta(get_the_ID(), 'show_what_listings', true); $listing_cat_commad = implode(", ", $listing_cat); ?> <?php $args = array( 'orderby' => 'meta_value', 'meta_key' => 'listing_date', 'order' => 'ASC', 'post_type' => 'events', 'posts_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => 'classes', 'field' => 'id', 'terms' => array( $listing_cat_commad ) ) ) ); $the_query = new WP_Query( $args ); and so on
if there is multiple term id’s selected then it doesn’t work. I have echo’d the variable and that looks fine – ie 4, 7, 8 – and if I just replace the variable with 4, 7, 8 in the terms => array then it works.
Any help would be much appreciated?
- The topic ‘[Resolved] WP_Query, using a variable in tax_query terms’ is closed to new replies.