Events to Appear in Random Order

Home Forums Calendar Products Events Calendar PRO Events to Appear in Random Order

Viewing 15 posts - 16 through 30 (of 31 total)
  • Author
    Posts
  • #1632975
    titusraj
    Participant

    HI Sky,

    This is how it is set up

    https://snag.gy/oatqiQ.jpg

    This is the code added

    https://snag.gy/ySGcB5.jpg

    Unfortunately no result.

    https://snag.gy/wKdYgC.jpg

    Titus

    #1633123
    Sky
    Keymaster

    Hi 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,
    Sky

    #1636798
    titusraj
    Participant

    Hi 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;
    }

    #1637385
    Sky
    Keymaster

    Hi 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,
    Sky

    #1637944
    titusraj
    Participant

    Hi 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

    #1638236
    Sky
    Keymaster

    Hi 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,
    Sky

    #1639004
    titusraj
    Participant

    Hi 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

    #1639485
    Sky
    Keymaster

    Hi 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,
    Sky

    #1639805
    titusraj
    Participant

    I 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.
    Titus

    #1640040
    Sky
    Keymaster

    Hi again,

    Are you also switching to the Twenty Seventeen theme to test? That’s the most likely culprit.

    Thanks,
    Sky

    #1640050
    titusraj
    Participant

    Strange , I have tried with twenty seventeen, have you tried this on a live environment on a different server?

    #1640901
    Sky
    Keymaster

    Hi 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,
    Sky

    #1643509
    titusraj
    Participant

    can 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.

    #1643727
    Sky
    Keymaster

    Hi 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,
    Sky

    #1644652
    titusraj
    Participant

    This reply is private.

Viewing 15 posts - 16 through 30 (of 31 total)
  • The topic ‘Events to Appear in Random Order’ is closed to new replies.