Home › Forums › Calendar Products › Events Calendar PRO › Events to Appear in Random Order
- This topic has 30 replies, 2 voices, and was last updated 5 years, 5 months ago by Sky.
-
AuthorPosts
-
September 28, 2018 at 2:12 am #1632975titusrajParticipant
HI Sky,
This is how it is set up
This is the code added
Unfortunately no result.
Titus
September 28, 2018 at 7:29 am #1633123SkyKeymasterHi again,
I have tested both of these snippets with the Twenty Seventeen theme. Seeing that you have “main events page” selected for your home page, the second one should work for you.
I would try once again switching to Twenty Seventeen, disable ALL other plugins, flush any caches and look again.
Thanks,
SkyOctober 3, 2018 at 3:09 pm #1636798titusrajParticipantHi Sky,
Do you meant this code?
Titus
<?php
/*
* Reorder events so that the ones that are running over a long period
* show up at the bottom of the list in a given view
*/
add_action( ‘pre_get_posts’, ‘push_older_events_to_bottom’, 500 );
function push_older_events_to_bottom( $query ) {
if ( is_front_page() ) {
$query->set( ‘orderby’, ‘meta_value’ );
$query->set( ‘meta_key’, ‘_EventStartDate’ );
$query->set( ‘order’, ‘DESC’ );
}
return $query;
}October 4, 2018 at 8:30 am #1637385SkyKeymasterHi again,
No. The latest snippet that is working for me is:
/*
* Reorder events on front page main calendar to be random.
*/
add_action( 'pre_get_posts', 'my_randomize_posts', 500 );
function my_randomize_posts( $query ) {if ( tribe_is_events_front_page() ) {
$query->set( 'orderby', 'rand' );
}return $query;
}
Thanks,
SkyOctober 4, 2018 at 7:30 pm #1637944titusrajParticipantHi Sky,
Unfortunately that did not work.
Lets forget random.
What about latest post on front page photo view?
Can this be done, I think it will be very useful to keep the site looking good with fresh content every time someone visits.
Maybe you can check with the guys who have worked with the plugin for a longer period.
Titus
October 5, 2018 at 9:02 am #1638236SkyKeymasterHi there,
Hooking into the “pre_get_posts” filter is the way to change the query. This is all standard WordPress stuff. See the Codex entry for more information about working with the query object: https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
The only thing specific to events here is the conditional, tribe_is_events_front_page(). This will return true when “Main Events Page” is set to be the homepage in WordPress > Settings > Reading.
Can you confirm for me that this is how you have your site set up?
The code I’ve been providing works on my end. If it is not working for you, either you are not pasting it in the correct place, or you are using different settings than what I am assuming when testing.
Can you try just replacing the conditional with “true” and see if that makes any difference?
Thanks,
SkyOctober 6, 2018 at 10:37 pm #1639004titusrajParticipantHi Sky,
Site is set up with Main Events Page as Home Page.
I am sure I have been pasting in the correct place.
Which word do I replace with “true”
Titus
October 8, 2018 at 7:43 am #1639485SkyKeymasterHi Titus,
You can just remove the conditional altogether. I just wanted to make sure that’s not where the issue was for you. But if you have “Main Events Page” set for “Home Page”, that’s probably not it.
Here are some screenshots showing the code I provided in my functions.php file, and then how it resolves on the front end of my site. You can see that each time I load the page, the events are in a different order.
I have my homepage set to “Main Events Page” and the default view set to “photo” just as you do.
I provide variations on this code to customers all the time, and am not aware of anything aside from a theme/plugin overriding the query that would prevent it from working if added to your site correctly.
My suggestion is to try switching to Twenty Seventeen and disable all plugins, flush any caches, and start from there. If you can’t get the code to work in that configuration, you may need to contact your host or have a WordPress developer take a look at what you’re trying to do.
Thanks,
SkyOctober 8, 2018 at 9:32 pm #1639805titusrajParticipantI am only using events calendar plugins ! Unless there is a conflict within your plugins.
Host is siteground, which is very good.
Have purged the cache.
Still does not work.
Will request again in a few months to see if there is any other solution.
TitusOctober 9, 2018 at 7:37 am #1640040SkyKeymasterHi again,
Are you also switching to the Twenty Seventeen theme to test? That’s the most likely culprit.
Thanks,
SkyOctober 9, 2018 at 7:46 am #1640050titusrajParticipantStrange , I have tried with twenty seventeen, have you tried this on a live environment on a different server?
October 10, 2018 at 8:34 am #1640901SkyKeymasterHi again,
You can try creating a quick WordPress instance on http://poopy.life
If you are able to recreate the issue there, let me know and I’ll take a look at what you’re doing.
Thanks,
SkyOctober 15, 2018 at 10:09 pm #1643509titusrajParticipantcan you please refer to another support engineer and see if they have a different code that might work.
Basically need to make the front page random, or ideally the latest additions. I am stuck with the same photo front page now and if it is a long event, it just stays on the front page.
October 16, 2018 at 8:20 am #1643727SkyKeymasterHi again,
Please note that we are limited in the amount of support we can provide for customizations such as this. We’re happy to help when it’s something we can quickly refer you to a snippet or documentation. If you’re not able to get the snippets we provide working, you’ll need to find a professional developer who can assist you.
We share snippets amongst each other, and the code I’ve provided is using basic WordPress functionality to modify the query. The only thing specific to our plugins in there is the conditional, which I recommended temporarily removing to troubleshoot. If it still doesn’t work for you without the conditional, I would suggest visiting the WordPress Codex or Developer’s Resources site to see how the hook and query object works, and you can modify it as needed.
I’m sorry I wasn’t able to help to your satisfaction, but I wish you luck getting it figured out.
Thanks,
SkyOctober 17, 2018 at 9:07 pm #1644652titusrajParticipantThis reply is private.
-
AuthorPosts
- The topic ‘Events to Appear in Random Order’ is closed to new replies.