Order events by gkevent_date_start

Responsive WordPress theme suitable for Schools, Colleges or educational websites.
GK User
Wed Sep 03, 2014 3:12 pm
Hi there,

Is it possible to order events in the events-list-1 or -2 by the custom field gkevent_date_start rather than the publication date (set by default) in order to display event in the order of happening rather than the order of publication.

Example here : http://www.esitc-cachan.fr/categorie/events-list-1/

Thanks by advance for your answer :)

Bertrand
User avatar
Fresh Boarder

GK User
Thu Sep 04, 2014 8:17 am
Hello,

Ufnortunately it's not possible without a lot of modifications. Events in this category are like normal posts but with additional fields (event block) and sorting is the same as in the default category.
User avatar
Moderator

GK User
Thu Sep 04, 2014 12:43 pm
Hello,

Ok. I will try by myself anyway.

I'll post it here in case it might help others

Bertrand
User avatar
Fresh Boarder

GK User
Mon Sep 08, 2014 1:18 pm
Hello, I found something to order events by gkevent_date_start custom field :

In category-events-list-1, replace :
Code: Select all
<?php while ( have_posts()  ) : the_post (); ?>


by

Code: Select all
<?php
//args
$args = array(
     'category_name' => 'events-list-1',
     'posts_per_page' => -1,
     'meta_key' => 'gk_event_date_start',
     'orderby' => 'meta_value',
     'order' => 'ASC'
     );

//query
$wp_query = new WP_Query( $args );

//loop
while( $wp_query->have_posts()  ): $wp_query->the_post();
?>


You can do the same modification for the category-events-list-2, replacing 1 by 2 in
Code: Select all
'category_name'
.

Nota : Take care to respect this date format : 2015-06-05 07:00. From 1 to 9, put a 0 before the date in order to keep the numerical ordering ;).
User avatar
Fresh Boarder

GK User
Wed Sep 10, 2014 8:50 am
Thank you for the solution, I'm sure that it will be very helpful for other users.
User avatar
Moderator

GK User
Wed Sep 24, 2014 11:54 am
Its interesting but it couldn't work on my website. After changes all posts from category are missing. There's only category's description. Did you change only category-events-list-1.php file or something else?
User avatar
Fresh Boarder

GK User
Sun Sep 28, 2014 10:50 am
eurocup wrote:Its interesting but it couldn't work on my website. After changes all posts from category are missing. There's only category's description. Did you change only category-events-list-1.php file or something else?


The same thing happened with me.
Can you please tell us how to rectify the same?
User avatar
Fresh Boarder


cron