php - WP Query, with ACF to NOT show posts with a date older than today -


morning all,

i'm attempting loop through posts in specific category if custom field (event_date) (acf) older today. query i'm using is:

$today = current_time('ymd'); $args = array( 'category' => 42, // events category 'post_status' => 'publish', // published 'posts_per_page' => '0', // unlimited posts per page 'meta_query' => array(     array(         'key' => 'event_date', // loop through posts when event date         'compare' => '>', // greater $today, ie in future         'value' => $today,      ) ), 'meta_key' => 'event_date', 'orderby' => 'meta_value', 'order' => 'asc', ); 

in acf, i've set saved date default (yymmdd) , i've set match $today var (ymd) yet it's still showing event 23rd june.

the client wanted them listed show events in date order, not show past events. i've got half working, 1 causing me issues believe should working. i've double checked in backend , looks good. may having blonde moment too...

any assistance appreciated!

thanks!

looking @ codex, , looks wp might have issue ordering meta_value consists of numbers. copied below:

'meta_value' - note 'meta_key=keyname' must present in query. note sorting alphabetical fine strings (i.e. words), can unexpected numbers (e.g. 1, 3, 34, 4, 56, 6, etc, rather 1, 3, 4, 6, 34, 56 might naturally expect). use 'meta_value_num' instead numeric values. may specify 'meta_type' if want cast meta value specific type. possible values 'numeric', 'binary', 'char', 'date', 'datetime', 'decimal', 'signed', 'time', 'unsigned', same in '$meta_query'. when using 'meta_type' can use meta_value_* accordingly. example, when using datetime 'meta_type' can use 'meta_value_datetime' define order structure.

so i'd try meta_value_num first see if works. if not, i'd cast meta_type date or datetime.


notes:

  • 'posts_per_page' => -1, show posts not 'posts_per_page' => '0',
  • 'cat' => 42, not 'category' => 42,

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -