Orderby question, with a twist…

Home Forums Calendar Products Events Calendar PRO Orderby question, with a twist…

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #235783
    Jason Emanuelson
    Participant

    I am trying to achieve a display of events, ordered by start date, starting with the current date. I have looked at the following forum topic (https://theeventscalendar.com/support/forums/topic/wp_query-events-with-date-year-filter/), but am not sure if I know how to apply it to an element. The theme is Enfold and their full-width-masonry layout element. It is a wonderful way to display upcoming events, if I could just get the ordering down. I managed to get it to allow sorting, but I only have a handful of sorting options. Here is the code I used to add the ordering ability to the admin. The code works in that I can order by various fields, including post date, but not event_date.

    if(!function_exists(‘avia_custom_query_extension’))
    {
    function avia_custom_query_extension($query, $params)
    {
    global $avia_config;
    if(!empty($avia_config[‘avia_custom_query_options’][‘order’]))
    {
    $query[‘order’] = $avia_config[‘avia_custom_query_options’][‘order’];
    }

    if(!empty($avia_config[‘avia_custom_query_options’][‘orderby’]))
    {
    $query[‘orderby’] = $avia_config[‘avia_custom_query_options’][‘orderby’];
    }

    unset($avia_config[‘avia_custom_query_options’]);

    return $query;
    }

    add_filter(‘avia_masonry_entries_query’, ‘avia_custom_query_extension’, 10, 2);
    add_filter(‘avia_post_grid_query’, ‘avia_custom_query_extension’, 10, 2);
    add_filter(‘avia_post_slide_query’, ‘avia_custom_query_extension’, 10, 2);
    add_filter(‘avia_blog_post_query’, ‘avia_custom_query_extension’, 10, 2);

    add_filter(‘avf_template_builder_shortcode_elements’,’avia_custom_query_options’, 10, 1);
    function avia_custom_query_options($elements)
    {
    $allowed_elements = array(‘av_blog’,’av_masonry_entries’,’av_postslider’,’av_portfolio’);

    if(isset($_POST[‘params’][‘allowed’]) && in_array($_POST[‘params’][‘allowed’], $allowed_elements))
    {
    $elements[] = array(
    “name” => __(“Custom Query Orderby”,’avia_framework’ ),
    “desc” => __(“Set a custom query orderby value”,’avia_framework’ ),
    “id” => “orderby”,
    “type” => “select”,
    “std” => “”,
    “subtype” => array(
    __(‘Default Order’, ‘avia_framework’ ) =>”,
    __(‘Title’, ‘avia_framework’ ) =>’title’,
    __(‘Random’, ‘avia_framework’ ) =>’rand’,
    __(‘Date’, ‘avia_framework’ ) =>’date’,
    __(‘Author’, ‘avia_framework’ ) =>’author’,
    __(‘Name (Post Slug)’, ‘avia_framework’ ) =>’name’,
    __(‘Modified’, ‘avia_framework’ ) =>’modified’,
    __(‘Comment Count’, ‘avia_framework’ ) =>’comment_count’,
    __(‘Page Order’, ‘avia_framework’ ) =>’menu_order’)
    );

    $elements[] = array(
    “name” => __(“Custom Query Order”,’avia_framework’ ),
    “desc” => __(“Set a custom query order”,’avia_framework’ ),
    “id” => “order”,
    “type” => “select”,
    “std” => “”,
    “subtype” => array(
    __(‘Default Order’, ‘avia_framework’ ) =>”,
    __(‘Ascending Order’, ‘avia_framework’ ) =>’ASC’,
    __(‘Descending Order’, ‘avia_framework’ ) =>’DESC’));
    }

    return $elements;
    }

    add_filter(‘avf_template_builder_shortcode_meta’, ‘avia_custom_query_add_query_params_to_config’, 10, 4);
    function avia_custom_query_add_query_params_to_config($meta, $atts, $content, $shortcodename)
    {
    global $avia_config;
    if(empty($avia_config[‘avia_custom_query_options’])) $avia_config[‘avia_custom_query_options’] = array();

    if(!empty($atts[‘order’]))
    {
    $avia_config[‘avia_custom_query_options’][‘order’] = $atts[‘order’];
    }

    if(!empty($atts[‘orderby’]))
    {
    $avia_config[‘avia_custom_query_options’][‘orderby’] = $atts[‘orderby’];
    }

    return $meta;
    }
    }

    I have reached out to Kriesi and they responded with the following:

    Hi solarmediapro!
    I’m sorry but “event date” is not a default wordpress orderby/order parameter: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters – and probably it require some additional tweaking and code customization to query the events based on the “event date”. I suggest to contact the plugin author – maybe they can provide some custom code for free and if not please hire a freelancer who can implement the event date query option.
    Best regards,
    Peter

    ***

    Can you help me figure this out? I honestly am not sure what direction to go, but know that it really should be possible. Is it not the expected that post date and event dates would be separate for obvious reasons, and that one might want to sort and filter by dates?

    I would be happy to share access with the site, so you could see the back-end as well.

    #236443
    Barry
    Member

    Hi!

    Great question. I do want to note first of all, though, that we are fairly limited in terms of helping out with custom development questions like this one. That said, we’d love to point you in the right direction if we can.

    Yes, it’s completely possible to order dates chronologically – it is in fact what we do on our upcoming events view (and we do the reverse in our past events view).

    Would it be viable for you to simply obtain a list of upcoming events, running earliest to latest, with a short snippet like this one – and then use the results to populate your template?

    	$args = array( 'eventDisplay' => 'upcoming' );
    	$events = tribe_get_events( $args );
Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Orderby question, with a twist…’ is closed to new replies.