Support

Account

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' );