Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1403167

    Hey, I have a client’s site showing Events Calendar listings using the Blog element (so I can filter by custom taxonomy). We have the below filter in functions.php helping with this and the below Event Time snippet in loop-index.php (see results at bottom of https://gobeyondhomes.org/property/evergreen-apartments/ or https://capture.dropbox.com/ZzvAMCqV9syOXzmS ). You can see how the events are listing/ordered by publish dates, as opposed to event dates/times — can you offer any guidance in getting the events to order by the event dates/time as opposed to publish dates? Thanks so much and lmk if you have any questions!

    add_filter('avia_blog_post_query', 'avia_blog_post_query_mod_events', 10, 2);
    function avia_blog_post_query_mod_events( $query, $params ) {
        $eventquery = array('paged' => false, 'eventDisplay' => 'list', 'tax_query' => $query['tax_query']);
        $upcoming = Tribe__Events__Query::getEvents( $eventquery, true);
    	$include = array();
    	foreach($upcoming->posts as $key => $event) {
    		$include[] = $event->ID;
    	}
            $query['tax_query'] = array();
    	$query['post__in'] = $include;
    	return $query;
    }
    //CALL EVENT TIME INSTEAD OF DATE IN BLOG ELEMENT
    					$time =  get_the_time( get_option( 'date_format' ) );
    					if(get_post_type(get_the_ID() == 'tribe_event')) {
    						$time = tribe_get_start_date(get_the_ID(), true);
    					} 
    					echo "<time class='date-container minor-meta updated' >" . $time . '</time>';
    //
    • This topic was modified 1 year, 7 months ago by sky19er.
    #1403355

    Hey sky19er,

    Thank you for the inquiry.

    Did you add the filter in the functions.php file? We tried to visit the site but it redirects to the login page requiring authentication. Please provide the login details in the private field.

    Best regards,
    Ismael

    #1404497

    Hmm, I thought I replied to this — guess I got distracted and never hit submit….Anyways! Yes, the filter’s in the functions file and the Event Time snippet’s in the loop-index — both are in the child theme. The example I listed in the original post is no longer valid, since those events have now passed, but here are a couple of other examples: https://gobeyondhomes.org/property/casa-dominguez/ and https://gobeyondhomes.org/property/morgan-place/

    Credentials below — thanks, Ismael!!

    #1404641

    Hi,

    The sorting might not be applying correctly because of the Properties taxonomy, which is what is used in the taxonomy query within the filter. How did you apply this taxonomy to the events?

    Best regards,
    Ismael

    #1404644

    Thanks, Ismael — looks like I added it with the CPT UI plugin (see https://capture.dropbox.com/s1Lk7UWcUheKvgfd), but I also just noticed this block of code at the bottom of my functions file (sorry I missed that the first time). Thanks again and lmk if you have any other questions.

    // ADD POST SORT OPTIONS TO ENFOLD ELEMENTS
    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_magazine_entries_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','av_magazine');
    
            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;
        }
    }
    #1405344

    Hi,

    We get a critical error after updating the functions.php file. We tried to access the server via FTP but are not able to get through using the info above. Would you mind reverting the site back to the most recent backup? Sorry for the inconvenience.

    Once the site is back, please replace the filter in the functions.php with the following code.

    /* query events by starting date */
    function avia_blog_post_query_mod( $query, $params ) {
            if(! is_singular( 'portfolio' ) ) 
            {
                return $query;
            }
    
    	$include = array();
    
    	$events = tribe_get_events( [
    		'posts_per_page' => $query["posts_per_page"],
    		'start_date'     => 'now',
    	] );
    
    	foreach($events as $event) {
    		$include[] = $event->ID;
    	}
    
    	unset($query['tax_query']);
    	$query['post__in'] = $include;
    
    	return $query;
    }
    add_filter('avia_blog_post_query', 'avia_blog_post_query_mod', 10, 2);
    

    Best regards,
    Ismael

    #1405415

    Sorry about the sftp info — below/private has a new password. Instead of reverting the whole site, I just uploaded restored the functions file. But replacing the ADD POST SORT OPTIONS TO ENFOLD ELEMENTS filter at the bottom of that file with the filter you provided didn’t seem to work, so I left the original filter in place.

    BTW, you’ll notice the Morgan Place page/url now seems to have some events at the bottom which aren’t formatting properly — I’m guessing that’s a separate issue due to staff not properly entering events, or something (I haven’t seen that issue before) — I’m guessing you can ignore that, for now.

    Thanks again and lmk if you have other questions.

    #1405483

    Hi,

    Thank you for the access.

    We modified the code in the functions.php file again and the changes seem to be working correctly. This is the final code.

    
    /* query events by starting date */
    function avia_blog_post_query_mod( $query, $params ) {
        if(! is_singular( 'portfolio' ) ) 
        {
            return $query;
        }
    
        $include = array();
        $posts = array();
    
        $events = tribe_get_events( [
            'posts_per_page' => 5,
            'start_date' => 'now',
            'orderby' => 'meta_value',
            'meta_key' => '_EventStartDate',
            'order' => 'DESC',
            'tax_query' => $query['tax_query']
        ] );
    
        foreach($events as $event) {
            $date = tribe_get_start_date( $event, false, 'j F Y' );
            $include[$event->ID] = $date;
        }
    
        asort($include);
    
        foreach($include as $key => $value) {
            $posts[] = $key;
        }
    
        unset($query['tax_query']);
        $query['orderby'] = 'meta_value';
        $query['order'] = 'ASC';
        $query['meta_key'] = '_EventStartDate';
        $query['post__in'] = $posts;
    
        return $query;
    }
    add_filter('avia_blog_post_query', 'avia_blog_post_query_mod', 10, 2);
    

    Best regards,
    Ismael

    #1405617

    Nice — thanks so much, Ismael — the ordering’s working, and that’s amazing, but it seems now the recurring events aren’t showing. For example, there should be recurring events showing on https://gobeyondhomes.org/property/wilmington-townhomes/. If I disable the functions file in the child theme, I can see the recurring events, but we’re getting that “nothing found” message when the functions file’s active. Do you have any idea why that might be? Thanks again.

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘using blog element for events calendar listings, need to order by event date’ is closed to new replies.