Black Friday sale! Get 25% off WPSP Pro! Discount automatically applied at checkout.

[Support request] Sorting Events Calendar Events by Event Start Date instead of Publish Date?

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Sorting Events Calendar Events by Event Start Date instead of Publish Date?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #14502
    Bodie J
    Participant

    I am using WP Show Posts to gloriously display Events Calendar Posts all over my website. I have a “This Week” Section on our homepage where I have an Events Calendar Shortcode showing this week’s events and below it, I have a WPSP shortcode doing the same but mostly just the featured images. My goal is to get the events to sort chronologically based on when they actually occur, not based on when the post I created them.

    I have the code below forcing my Events Calendar Admin to always sort the events chronologically with the next event to occur on the top of the list. Is there a way I can match this sorting using WPSP on my homepage?

    /* Sort Events by Ascending as a Default */
    function order_events_by_next_start_date( $wp_query ) {
      if (is_admin()) {
        $post_type = $wp_query->query['post_type'];
    
        if ( $post_type == 'tribe_events') {
          $wp_query->set('orderby', 'start_date');
          $wp_query->set('order', 'ASC');
        }
      }
    }
    add_filter('pre_get_posts', 'order_events_by_next_start_date');

    The start_date is the date that I would like to have WPSP sort by, and then sort ascending.

    Is this possible? You can see how it is now at the link below:

    https://hcf.cc

    Thanks

    Bodie

    • This topic was modified 7 months, 3 weeks ago by Bodie J.
    #14516
    Tom
    Keymaster

    Hi there,

    You should be able to add that to the shortcode.

    Something like this:

    [wp_show_posts id="123" settings="orderby=start_date&order=ASC"]

    Let me know 🙂

    #14520
    Bodie J
    Participant

    Tom,

    Thanks for the reply, but for some reason it doesn’t seem to work. Is there any particular settings I should set in the “More Settings” section?

    I am trying to go for the same effect on both of these pages.

    https://hcf.cc/#this-week
    https://hcf.cc/services/

    I simply want to organize them chronologically with the next one coming up be the first one in the list. Your shortcode adjustment should work but it doesn’t seem to? I wrote the date in the title so it is easier to see what day they occur on. For whatever reason, they don’t seem to be ordering by start_date.

    What else should I try?

    Appreciate your help, as always.

    Bodie

    #14548
    Tom
    Keymaster

    Weird, let’s debug to see if the parameters are making it through:

    add_filter( 'wp_show_posts_shortcode_args', function( $args ) {
        var_dump($args);
        return $args;
    } );

    What does that output above your list?

    #14550
    Bodie J
    Participant

    Ok here we go:

    This was above the “THIS WEEK” Section on the homepage: https://hcf.cc/#this-week

    array(6) { ["order"]=> string(3) "asc" ["orderby"]=> string(10) "start_date" ["post_type"]=> string(12) "tribe_events" ["posts_per_page"]=> int(8) ["post_status"]=> array(1) { [0]=> string(7) "publish" } ["tax_query"]=> array(1) { [0]=> array(4) { ["taxonomy"]=> string(8) "post_tag" ["field"]=> string(4) "slug" ["terms"]=> array(1) { [0]=> string(9) "this-week" } ["operator"]=> string(2) "IN" } } }

    and this was on the Online Services Page: https://hcf.cc/services/

    array(7) { ["order"]=> string(3) "asc" ["orderby"]=> string(10) "start_date" ["post_type"]=> string(12) "tribe_events" ["posts_per_page"]=> int(10) ["paged"]=> int(0) ["post_status"]=> array(1) { [0]=> string(7) "publish" } ["tax_query"]=> array(1) { [0]=> array(4) { ["taxonomy"]=> string(8) "post_tag" ["field"]=> string(4) "slug" ["terms"]=> array(1) { [0]=> string(15) "online-services" } ["operator"]=> string(2) "IN" } } }

    I left them on the page for now if you want to see.

    Thanks

    #14586
    Tom
    Keymaster

    Can you try ASC instead of asc?

    Everything else looks good to me.

    #19675
    Gary
    Participant

    I am having the same problem. My events will not sort by ‘Upcoming’ order.

    I have debugged and get the following:

    array(5) { ["order"]=> string(4) "desc" ["orderby"]=> string(15) "event_dates_asc" ["post_type"]=> string(8) "gd_event" ["posts_per_page"]=> int(10) ["post_status"]=> array(1) { [0]=> string(7) "publish" } }

    I am using this shortcode: [wp_show_posts id="14475" settings="orderby=event_dates_asc" ]

    The event_dates_asc is custom meta from Geodirectory.

    #19711
    elvin
    Participant

    Hi Gary,

    Can you start a new topic and provide the details on it? Thanks. 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.