Support

Account

Home Forums General Issues Querying post with a date picker filed older than 15 days

Solving

Querying post with a date picker filed older than 15 days

  • Hey, guys!

    I have a date picker field and I am trying to query posts with this date older than 15 days.
    I came up with some code, but the thing is that is not working accurate. I shal be very greatfull if someone can provide some help.

    Here is my code:

    
    $date_args = array(
            'post_type'   => 'bransamente',
            'meta_key' => 'data_depunere_bs',
            'posts_per_page' => -1,
            'orderby' => 'meta_value_num',
            'order' => 'ASC',
    		'tax_query' =>  array (
    		    array(
          			'taxonomy' => 'status_bransament', 
    			    'terms' => 'bransament-rezolvat', 
          			'field' => 'slug', 
          			'operator' => 'NOT IN', 
        		),
      		),
            'meta_query'=> array(
                array(
                  'key' => 'data_depunere_bs',
                  'compare' => '<=',
                  'value' => date("j F Y", strtotime("-15 days")),
                  'type' => 'DATE'
                )
            ),
        );
    

    Thanks in advance.

  • How are you values saved in the ACF Field group? You need to match your code with the Return format in the field.

    What happend if your change “j F Y” to “Ymd”?

  • 
    'value' => date("Ymd", strtotime("-15 days")),
    

    ACF stores dates in the database in the format above

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Querying post with a date picker filed older than 15 days’ is closed to new replies.