Tagged: datepicker order WP_Query
- This topic has 1 reply, 2 voices, and was last updated 4 years, 6 months ago by
Steve.
-
AuthorPosts
-
-
August 5, 2017 at 11:03 am #8345
JuanParticipantHey all,
i’m trying to make a schedule based on CPT called ‘events’.
I have all the info already storaged.I created a metabox with a group of fields to fill in all the event data. This is the code:
<?php /* Title: Info Post Type: event Meta box: true Order: 0 */ piklist('field', array( 'type' => 'group' ,'field' => 'module_group' ,'label' => 'Add blocks' ,'value' => 'none' ,'template' => 'field' ,'fields' => array( array( 'type' => 'datepicker', 'field' => 'event_date', 'label' => 'Date', 'columns' => 6, 'attributes' => array( // Pass HTML5 attributes in the attributes array 'required' => 'required', ) ,'options' => array( 'dateFormat' => 'dd M yy' ) ) ,array( 'type' => 'time', 'field' => 'event_time', 'label' => 'Time', 'columns' => 6, 'options' => array( 'time:Format' => 'h: s' ) ) ,array( 'type' => 'select' ,'field' => 'module_select' ,'label' => 'Select type of Event' ,'columns' => 6 ,'choices' => array( 'none' => '…' ,'select_actividad' => 'Activity' ,'select_film' => 'Films' ) ) ,array( 'type' => 'select', 'field' => 'activity', 'label' => 'Select an Activity', 'columns' => 12, 'value' => '', 'choices' => array('' => '— Select one —') + piklist(get_posts(array( 'post_type' => 'actividades', 'numberposts' => -1 )), array('ID', 'post_title') ) ,'conditions' => array( array( 'field' => 'module_group:module_select' ,'value' => 'select_actividad' ) ) ) ,array( 'type' => 'select', 'field' => 'films', 'label' => 'Select a Film', 'columns' => 12, 'value' => '', 'choices' => array('' => '— Select one —') + piklist(get_posts(array( 'post_type' => 'film', 'numberposts' => -1, 'suppress_filters' => 0 )), array('ID', 'post_title') ) ,'conditions' => array( array( 'field' => 'module_group:module_select' ,'value' => 'select_film' ) ) ) , array( 'type' => 'select', 'field' => 'location', 'label' => 'Select Location', 'columns' => 12, 'value' => '', 'choices' => array('' => 'Select location …') + piklist(get_posts(array( 'post_type' => 'location', 'numberposts' => -1, 'suppress_filters' => 0 )), array('ID', 'post_title')) ) ,array( 'type' => 'textarea' ,'field' => 'write-location' ,'label' => __('Or, write location name and address :') ,'columns' => 12 ) ,array( 'type' => 'text' ,'field' => 'event_tickets' ,'label' => __('Tickets link') ,'columns' => 12 ) ,array( 'type' => 'text' ,'field' => 'event_subtitles' ,'label' => __('Subtitles / Language') ,'columns' => 12 ) ,array( 'type' => 'text' ,'field' => 'event_price' ,'label' => __('Price €') ,'columns' => 12 ) ) ));What im trying to achieve is to display the events ordered by ‘event_time’ and ‘event-time’.
I am using the ‘meta_key’ argument to pass an array to the loop with no success at all. code:
$args = array( 'post_type' => 'event', 'meta_key' => 'event_date', // name of custom field 'orderby' => 'meta_value', "order" => 'ASC', "posts_per_page" => 1, ); print_r($args); $loop = new WP_Query($args); while ( $loop->have_posts() ) : $loop->the_post(); { }thanks for any further help!
-
August 12, 2017 at 10:34 pm #8350
SteveKeymasterAdd the ‘field’ parameter to a group field saves all the data in one array… which you cannot query because event_date is actually in the database as module_group[‘event_date’].
Remove ‘field’ => ‘module_group’, and the data will save as individual fields, and then you should be able to query against event_date.
-
-
AuthorPosts
- You must be logged in to reply to this topic.