Support » Developing with WordPress » test a date field in query_posts

  • Hi there,

    I use CPT ‘specials’ with a custom field ‘special-end’ (date)

    I make a query to display these posts

    
    $args = array(
    		'post_type' => 'specials', 
    		'orderby' => 'special-end',
    		'order' => 'ASC',
    		'posts_per_page'=> '12',  
    	);
    

    But how could i only get posts where ‘special-end’ is greater than today ?

    Thanks for your help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    I think you can get the date range posts using date query.

    Thanks,
    TD

    Hi TD and thanks.
    I read some posts about date query but i don’t think it’s what i need. date query works with the post creation date ou revision date.
    I want filter my posts using a custom field.
    Regards,

    Finally simply works like this

    
    	$args = array(
        	'post_type' => 'promotion',
    		'meta_key' => 'fin-promo',
    		'meta_value' => date('Ymd'),
    		'meta_compare' => '>',
    		'orderby' => 'fin-promo',
    		'order' => 'ASC'
    	);
    

    I create my field fin-promo with ACF and the internal format is dmY.
    Hope this can help someone.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘test a date field in query_posts’ is closed to new replies.