Support

Account

Home Forums ACF PRO WP_Query and sub-fields Reply To: WP_Query and sub-fields

  • James; one thing I have just noticed though is that, if I set the date of the show to the Monday just passed and the Monday coming, both dates echo out.
    (As this example show may be ‘on air’ every Monday of every week)

    How would I edit my code so that it only displays the show for the Monday of ‘this week‘?

    // Get dates for the week, starting on a monday
    $monday    = strtotime('last monday', strtotime('tomorrow'));
    $tuesday   = strtotime('+1 days', $monday);
    $wednesday = strtotime('+2 days', $monday);
    $thursday  = strtotime('+3 days', $monday);
    $friday    = strtotime('+4 days', $monday);
    $saturday  = strtotime('+5 days', $monday);
    $sunday    = strtotime('+6 days', $monday);
    
    $mon = date( 'Ymd', $monday );
    etc...
    
    						<?php
    							function my_posts_where( $where ) {
    								$where = str_replace("meta_key = 'schedule_time_slot_%", "meta_key LIKE 'schedule_time_slot_%", $where);
    								return $where;
    							}
    							add_filter( 'posts_where', 'my_posts_where' );
    						?>
    
    						<?php
    							$args = array(
    								'posts_per_page' => -1,
    								'post_type'      => 'schedule',
    								'meta_key'       => 'schedule_time_slot_%_schedule_date',
    								'meta_query'     => array(
    									array(
    										'key'     => 'schedule_time_slot_%_schedule_date',
    										'compare' => '=',
    										'value'   => $mon,
    										'type'    => 'DATE',
    									)
    								)
    							);
    						?>

    Many thanks