Do Meta Query based on Custom Field
-
I’m trying to filter my query by using a custom field I add to a page. I’m filtering by year. By adding a custom field “year” and the value. The problem seems to be that it’s not outputting the actual value into my query. I know this is the case because if I change ‘value’ => $year to ‘value’ => 2012 it changes my results. What am I doing wrong?
My code is
<?php $year = get_post_meta($post->ID, 'year', true); ?> <?php $args = array( 'post_type' => 'cattle_champion', 'posts_per_page' => -1, 'order' => 'DESC', 'meta_query' => array( array( 'key' => 'show_year', 'value' => $year, 'compare' => 'LIKE', ), array( 'key' => 'show_level', 'value' => 'county', 'compare' => 'LIKE', ) ) ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post() ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Do Meta Query based on Custom Field’ is closed to new replies.