Home › Forums › General Issues › WP_Query based comparing TWO repeater field values › Reply To: WP_Query based comparing TWO repeater field values
Hey Guys,
I figured out the issue. Basically, in my previous post I had the greater than & less than comparison switched AND also my filter was not properly string replacing both sql where statements. Here’s the code I have working now, hopefully it helps someone out there:
WP_Query args:
//Serial# Meta Query $args = array( 'post_type' => 'manual', 'numberposts' => - 1, 'suppress_filters' => false, 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'files_%_start_range_num', 'value' => intval( $_GET['s'] ), 'type' => 'NUMERIC', 'compare' => '<=' ), array( 'key' => 'files_%_end_range_num', 'value' => intval( $_GET['s'] ), 'type' => 'NUMERIC', 'compare' => '>=' ) ), );
Filter:
// custom filter to replace '=' with 'LIKE' // see: http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/ function acf_posts_where( $where ) { $where = str_replace( "meta_key = 'files_%", "meta_key LIKE 'files_%", $where ); return $where; } add_filter( 'posts_where', 'acf_posts_where' );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.