WP_query on field groups not working unless additional custom field added to pos
-
Hi there
I’m running into an issue with trying to run a custom WP_query using custom field values. I’ve got a custom field group (‘event fields’) attached to all posts. In this group is a field called ‘eventdate’. My query is supposed to get upcoming or previous events depending on the page being accessed.
The problem is that the query doesn’t work unless I add a separate custom field to the post to hold “eventdate” and manually enter a the date string. Obviously this is redundant and I can’t use the datepicker widget.
Not sure what I’m missing here.
$currentdate = date("Y-m-d"); $wp_query = new WP_Query(array( 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'eventdate', 'compare' => '>=', 'value' => $currentdate, 'type' => 'DATE')), 'meta_key' => 'eventdate', 'orderby' => 'meta_value', 'order' => 'ASC' ));
Once the query runs successfully, I’m able to use the_field(‘eventdate’) without any issues.
- The topic ‘WP_query on field groups not working unless additional custom field added to pos’ is closed to new replies.