Support

Account

Home Forums Add-ons Repeater Field How do I query a repeater which uses recurring dates? Reply To: How do I query a repeater which uses recurring dates?

  • I have been testing with the following events and dates…

    Test 1

    23/05/2015 – 23/05/2015
    25/05/2015 – 29/05/2015

    Test 2

    24/05/2015 – 24/05/2015

    The trouble is that the following code is returning Test 1 and Test 2 for the date range of 24/05/2015 – 24/05/2015 when only Test 2 should be returned

    <?php
    
    		// filter
    		function my_posts_where( $where ) {
    	
    			$where = str_replace("meta_key = 'event_dates_%", "meta_key LIKE 'event_dates_%", $where);
    	
    			return $where;
    		}
    	
    		add_filter('posts_where', 'my_posts_where');
    
    		$args = array (
    		    'post_type' => 'event',
    		    'meta_query' => array(
    			    'relation'		=> 'AND',
    				array(
    			        'key'		=> 'event_dates_%_start_date',
    			        'compare'	=> '<=',
    			        'value'		=> '20150524',
    			    ),
    			     array(
    			        'key'		=> 'event_dates_%_end_date',
    			        'compare'	=> '>=',
    			        'value'		=> '20150524',
    			    )
    		    ),
    		);
    
    		$the_query = new WP_Query( $args );
    
    ?>