Home › Forums › Calendar Products › Events Calendar PRO › orderby published
- This topic has 11 replies, 2 voices, and was last updated 11 years ago by
George.
-
AuthorPosts
-
March 5, 2015 at 5:10 am #946117
Simon
ParticipantHi,
I’ve tried searching for the answer to this, but the answers were either out of date or didn’t work.
Simply, on the front end I want events to appear in the order in which they were published.
ie. not by start date.I’m looking for something to add to functions.php, but I think this should be a feature (maybe it is and I missed it). The site owners are all pretty unanimous that they want this feature.
Many thanks
March 8, 2015 at 1:22 am #946754Simon
ParticipantAny news?
March 8, 2015 at 11:42 pm #946829Simon
ParticipantHi,
Is there something to add to functions.php to make events appear in the order in which they were published?
Many thanks
March 9, 2015 at 9:36 am #946976George
ParticipantHey Simon! I’m really sorry about the delay, I swear I posted a question to this ticket on Saturday (March 7), I don’t know what happened – maybe I typed it up and thought I’d submitted it, but actually hadn’t, then switched to another support ticket and lost the post or something.
I’m really sorry Simon – my original post was one where I was curious about some more details about what you’re trying to do exactly.
For example – when you say “Front end”, do you mean on your main “Events” pages like the Month View, List View, Week View, etc.? Or do you mean elsewhere in your blog loop or something?
Be as specific as possible and let me know exactly where you’re trying to get the events to display this way – changing the display ordering of the events on main Events View pages is quite tricky, but elsewhere it’s much simpler.
One thing that might be helpful is our code snippet here → https://theeventscalendar.com/knowledgebase/order-events-in-main-blog-loop-by-post-date/
If you try out that code, how do things behave for you?
Thanks,
GoergeMarch 9, 2015 at 9:46 am #946980Simon
ParticipantHi George,
No worries : ) Luckily this is one of many items on my task list for this client.
It’s the view on this page ie. list view.
I think that snippet is for a different loop.
Thanks,
SimonMarch 9, 2015 at 10:32 am #946995George
ParticipantHey Simon,
Altering the events order for some of the core calendar views like is actually quite difficult to do, and could have a lot of negative consequences on how other aspects of the plugin function.
To change the sorting, if you’re really interested, it might be possible by using the pre_get_posts() function not unlike that original snippet I shared with you, but I played around with this for quite some time on my local test site and was not able to get the main List View loop looking this way.
If possible, I’d recommend not using one of the core Events views and instead maybe making a custom page template in your theme, and then just querying for events yourself, without even having to worry about all the specific time-oriented ordering that Events Calendar does in its core Events views and in wrapper functions like tribe_get_events(). In other words, you’d probably have better luck just using WordPress’ own get_posts() function directly, and specifying the tribe_events post type.
Here’s an example of that in a Gist for you to take and play around with → https://gist.github.com/momnt/db40abff79157cb4141a
I would agree with you if you were to argue that this should be simpler – I’m sorry it’s not, or if it is but I’m just missing something here, then I’m sorry for that too 🙂
Please play around with this and look into using custom page templates, a simpler solution like this that you make yourself may seem more work up front but might save a light of random unexpected headaches that might pop up by trying to forcefully alter the Events core views’ order parameters.
Let me know what you think Simon, sorry to disappoint here.
— George
March 9, 2015 at 11:09 am #947006Simon
ParticipantHey George,
Thanks so much for looking into it : )
Since most of that site is built with custom templates I think your idea of simply building another loop is great. I’ll look at your gist and do a few tests and report back here. Will leave the thread open for now.
Thanks again!
SimonMarch 9, 2015 at 5:47 pm #947115George
ParticipantThanks for understanding Simon – and for your patience with my delayed reply!
It’s really just my opinion that trying to mess all the core Views orderby functionality is not worth it – there’s a lot in the plugin that depends on the specific date ordering of events.
However, if that does turn out to be something you really need for your site, I can reach out to a more well-versed Dev on our team for some deeper input on how to go about enabling this.
Thanks for being cool, keep us posted on your project!
– George
March 13, 2015 at 1:23 am #948086Simon
ParticipantHi George,
Ok, finally got around to trying it. Using your code I made a page template in Genesis which lists events in published order: http://simonbarnett.co.za/artthrobtests/artthrob-events-2/
It works in terms of the order, but do you have a more complete template that displays the events in the same way that the plugin displays them in list view?
As far as I understand it the plugin builds the loop using template parts which are probably not available to normal page templates at that point of code execution, so I’d either need:
A more complete page template, if you perhaps have one
– or –
A way of doing this with a plugin templateI can probably reconstruct a page template, but I just thought it best to ask to save time, so if you don’t have one, then don’t stress : )
Regards,
SimonMarch 13, 2015 at 8:39 am #948159George
ParticipantHey Simon,
I’m glad you’ve got things sort-of working – for the next step, the good news is that you should indeed be able to use exact or similar templates to the ones that are already inside The Events Calendar.
In a nutshell, all of the front-end template views for The Events Calendar are in the folder /views in the main plugin folder (which is /wp-content/plugins/the-events-calendar by default).
Now, if you check out our official themer’s guide for example – https://theeventscalendar.com/knowledgebase/themers-guide/ – the way the plugin’s templating system works is that it first looks for a folder in your theme or child theme called /tribe-events. If it finds a version of the view in this folder, then it uses that, or else it defaults back to the /views folder within its own plugin files.
Does that make sense?
If not, check that themer’s guide out for a better understand of the “hierarchy” here.
But in either case, the whole reason I mention all of this stuff to begin with is that we need to ensure your custom-loop page template loads views appropriately.
With everything I said here, basically what you can do is move whatever “views” template files from the TEC plugin /views folder into your theme’s /tribe-events folder – if you want, you can even just duplicate all of the files.
Ensure that you use all the same file names, and sub-folder structure and sub-folder names too!
Finally, once all these template files exist in your theme, you can then go about using the function get_template_part() in your custom page template, to load the Events views you need – for inspiration on what things to load in what order, check out the originals in the plugin and do a “Search” through the plugin code to see where those file names are being included in the plugin.
If this all sounds a bit tricky, I’m sorry – and I’m sorry for how long this is, too. Please let me know if any specific thing needs more clarification or if you run into trouble along the way.
Thanks for your patience Simon!
Cheers,
George-
This reply was modified 11 years, 1 month ago by
George.
March 17, 2015 at 11:36 am #948921Simon
ParticipantHi George,
I ran out of time and simply flipped the order of events, most recent at the top, by cobbling together this function:
function tribe_past_reverse_chronological ($post_object) { if( tribe_is_past() || tribe_is_upcoming() && !is_tax() ) { $post_object = array_reverse($post_object); } return $post_object; } add_filter('the_posts', 'tribe_past_reverse_chronological', 100);They are happy with it, so I’m marking this as resolved.
Thanks so much for your help : )Kind regards,
SimonMarch 18, 2015 at 7:58 am #949123George
ParticipantOkay, thanks for sharing the update Simon. Best of luck with your site.
George
-
This reply was modified 11 years, 1 month ago by
-
AuthorPosts
- The topic ‘orderby published’ is closed to new replies.
