Support

Home Forums Custom Files Add-on (EE3) Order by start_date & start_time in wp_query

Order by start_date & start_time in wp_query

Posted: August 15, 2013 at 4:45 pm

Viewing 2 reply threads


Hugo Azzolini

August 15, 2013 at 4:45 pm

Hi.

I have a page with a list of events ordered by the start date, but not the start time: http://dppad.com/demo/orlandophil/?page_id=24

The code that produces this list is:

<code>global $post, $wp_query;
                    // define some arguments for our Event Espresso query
                    $args = array(
                            &#039;post_type&#039; =&gt; &#039;espresso_event&#039;,
                            &#039;meta_key&#039; =&gt; &#039;event_start_date&#039;,
                            &#039;posts_per_page&#039; =&gt; -1,
                            &#039;meta_query&#039; =&gt; array(
                                array(
                                    &#039;key&#039; =&gt; &#039;event_start_date&#039;,
                                    &#039;value&#039; =&gt; date(&#039;Y-m-d&#039;),
                                    &#039;compare&#039; =&gt; &#039;&gt;=&#039;, // compares the event_start_date against today&#039;s date so we only display events that haven&#039;t happened yet
                                    &#039;type&#039; =&gt; &#039;DATE&#039;
                                    )
                                ),
                            &#039;orderby&#039; =&gt; &#039;meta_value&#039;,
                            &#039;order&#039; =&gt; &#039;ASC&#039; // change this to ASC if you want newer events on top
                        );</code>

Can you recommend a modification to the query that will order the events by start date, but also by start time (so that matinee performances will appear before their corresponding evening performance).

Thanks.


Sidney Harrell

August 15, 2013 at 10:28 pm

I think you would have to change line 506 of includes/event-management/insert_event.php to:

add_post_meta($post_id, 'event_start_date', $start_date . ' ' . date("H:i", strtotime($start_time)));

and line 616 of includes/event-management/update_event.php to:

update_post_meta($post_id, 'event_start_date', $start_date . ' ' . date("H:i", strtotime($start_time)));

and line 646 of the same file to:

add_post_meta($post_id, 'event_start_date', $start_date . ' ' . date("H:i", strtotime($start_time)));

and line 22 of post-type-samples/page-event_list.php to:

'value' => date('Y-m-d H:i'),

Then you’ll have to resave your events to get your post data updated. Then it should order the posts by date and time.


Hugo Azzolini

August 16, 2013 at 8:01 am

Worked like a charm.

Any recommendations on accomplishing this in an update-proof way?

Viewing 2 reply threads

The support post ‘Order by start_date & start_time in wp_query’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso