Nicholas Rios

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 25 total)
  • Author
    Posts
  • in reply to: Help with tribe_events_query_posts_orderby filter #1067242
    Nicholas Rios
    Participant

    Looks like it works. That’s awesome, better than having to change the setting. Thanks a bunch Brian.

    Writing out all the code required for anyone else that may need it in the future.

    How to make The Events Calendar display events in the order in which they were published.

    function change_tribe_query_orderby($order_sql) {
        $order_sql = "wp_posts.post_date DESC";
    
        return $order_sql;
    }
    
    // Remove recurrence-collapse-sql logic
    remove_filter( 'posts_request', array( 'Tribe__Events__Pro__Recurrence_Meta', 'recurrence_collapse_sql' ), 10 );
    // Add filter to force orderby post_date
    add_filter( 'tribe_events_query_posts_orderby', 'change_tribe_query_orderby' );
    
    // (...Run the custom WP_Query here...)
    
    // Restore recurrence-collapse-sql logic
    add_filter( 'posts_request', array( 'Tribe__Events__Pro__Recurrence_Meta', 'recurrence_collapse_sql' ), 10, 2 );
    // Remove filter forcing orderby post_date
    remove_filter( 'tribe_events_query_posts_orderby', 'change_tribe_query_orderby' );
    
    in reply to: Help with tribe_events_query_posts_orderby filter #1067068
    Nicholas Rios
    Participant

    Well this has been an adventure, but I think I’ve found the issue.

    In short, the “Recurring event instances. Show only the first instance of each recurring event (only affects list-style views)” setting has to be UNCHECKED in order for the tribe_events_query_posts_orderby filter to work, possibly only on custom queries but maybe other instances also.

    I did a dump of the $wp_query global where the filter should have been working and took a look at the request portion and then searched through the plugin code base to see where it was coming from.

    It looks like Tribe__Events__Pro__Recurrence_Meta::recurrence_collapse_sql() is somehow overriding it. I’m not 100% sure this is a bug, but I would expect that this function should respect the query filter, or perhaps it needs another early return conditional before it hits the query.

    -Will

    in reply to: Help with tribe_events_query_posts_orderby filter #1066385
    Nicholas Rios
    Participant

    And yes, it’s custom.

    in reply to: Help with tribe_events_query_posts_orderby filter #1066367
    Nicholas Rios
    Participant

    Yea, that’s exactly it.

    in reply to: Help with tribe_events_query_posts_orderby filter #1065991
    Nicholas Rios
    Participant

    It was created quite a while back, I can’t recall if it was based on the Tribe code from back then.

    in reply to: Help with tribe_events_query_posts_orderby filter #1065989
    Nicholas Rios
    Participant

    I apologize for the formatting. Would you prefer I drop the code into a pasting site?

    function change_tribe_query_orderby($order_sql) {
    	$order_sql = "wp_posts.post_date DESC";
    
        return $order_sql;
    	
    	//global $wpdb;
    	//return "$wpdb->posts.post_date DESC";
    }

    Then from the widget:

    
    	$cache = wp_cache_get('widget_new_events', 'widget');
    
    	if ( !is_array($cache) )
    		$cache = array();
    
    		if ( ! isset( $args['widget_id'] ) )
    			$args['widget_id'] = $this->id;
    
    		if ( isset( $cache[ $args['widget_id'] ] ) ) {
    			echo $cache[ $args['widget_id'] ];
    			return;
    	}
    
    	ob_start();
    	extract($args);
    
    	$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'New Events' );
    	$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    	$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 10;
    		
            if ( ! $number ) $number = 4;
    
            add_filter( 'tribe_events_query_posts_orderby', 'change_tribe_query_orderby', 99 );
    		$query_args = array(
                'post_type' =>'tribe_events',
                'posts_per_page' => $number,
                'tax_query' => array(
                    array(
                        'taxonomy' => 'tribe_events_cat',
                        'field' => 'id',
                        'terms' => 30
                    )
                 ),
    		'no_found_rows' => true,
    		'orderby' => 'date',
    		'order'   => 'DESC'
            );
            $r = new WP_Query($query_args);
            remove_filter( 'tribe_events_query_posts_orderby', 'change_tribe_query_orderby', 99 );
    
    	if ($r->have_posts()) :
            
    	echo $before_widget;
    	if ( $title ) echo $before_title . $title . $after_title; ?>
    
            <ul class="new-event-list">
                <?php while ( $r->have_posts() ) : $r->the_post(); ?>
                    <?php if('tribe_events' === get_post_type() ) { ?>
                        <?php $event_link = tribe_get_event_link(); ?>
                        <li class="new-event-li"> <a class="new-event-title" href="<?php echo $event_link; ?>">
                            <?php the_title(); ?>
                        </a> <a class="new-event-date" href="<?php echo $event_link; ?>"><?php echo tribe_get_start_date( get_the_ID() , false, 'M j, Y' ); ?></a> </li>
                    <?php } ?>
                <?php endwhile; ?>
            </ul>
    <?php 
        echo $after_widget;
          
        wp_reset_postdata();
        endif;
    
        $cache[$args['widget_id']] = ob_get_flush();
        wp_cache_set('widget_new_events', $cache, 'widget');

    Note, it doesn’t seem like a caching issue as I’ve taken a look at the query and it doesn’t ever seem to be correct.

    in reply to: Help with tribe_events_query_posts_orderby filter #1065937
    Nicholas Rios
    Participant

    This reply is private.

    in reply to: Help with tribe_events_query_posts_orderby filter #1065936
    Nicholas Rios
    Participant

    Hey, sorry for any confusion in the original post.

    This is for a single query, only used once (widget on frontpage). The purpose is to show a “Just Announced” section (thus the need to change orderby to post_date instead of _EventStartDate).

    The query is also setting a specific category, but that part isn’t being filtered by TEC.

    in reply to: 3.1.0 Update: Event List Widget Broken #970891
    Nicholas Rios
    Participant

    Are you overriding list-widget.php? If so make sure to include the new lines near the beginning:

    $events_label_plural = tribe_get_event_label_plural();
    
    $posts = tribe_get_list_widget_events();
    in reply to: Request: New capability for tribe_event_settings #724390
    Nicholas Rios
    Participant
    in reply to: Months not advancing in Safari #702104
    Nicholas Rios
    Participant

    https://gist.github.com/ckpicker/8689212

    is the way that I just disabled the AJAX to skirt the issue. The suggestion comes from this thread: https://theeventscalendar.com/support/forums/topic/ajax-in-calendar-view-not-working/

    There is also this solution to a similar issue that might help some people:
    https://theeventscalendar.com/support/forums/topic/events-calendar-pro-month-3-4-not-switching-ajax-related/

    in reply to: Next / Previous Links not working in Calendar View #702099
    Nicholas Rios
    Participant
    in reply to: What is the page title filter? #556815
    Nicholas Rios
    Participant

    Got it, thanks.

    in reply to: What is the page title filter? #548641
    Nicholas Rios
    Participant

    https://theeventscalendar.com/support/forums/topic/yoast-ecl/

    This contains the solution, specifically a variation of: https://gist.github.com/jo-snips/3710617

    If I wasn’t only trying to change the main page, what I think I would do is filter wpseo_title with the above code combined with maybeAddEventTitle.

    in reply to: What is the page title filter? #548258
    Nicholas Rios
    Participant

    OK you caught me. Here are the various situations:

    1- 2014 WP Theme, no other plugins: “Events this month | %sitename” on landing page calendar, otherwise (navigating in calendar): “Events for (date) | %sitename”
    2- 2014 WP Theme, add WordPress SEO plugin: “Events | %sitename” on landing page calendar, otherwise: “Events for (date) | %sitename”
    3- Genesis child theme (tested with just framework as well) activated, no other plugins: “Events this month” on landing page calendar, otherwise: “Events for (date)” (no sitename on either)
    4- Genesis child theme, WordPress SEO: “Events – %sitename”, otherwise “Events for (date) |” (missing sitename on second)

    I’m not sure where the >> separator came from, or where it went. My original hope was to just replace where the word “Events” wherever it was entered in by ECP. I’m kind’ve confused where the simple “Events” one is coming from because I don’t see it even as an option in the plugin (only variations of it with the date).

    Thanks for looking into it Barry.

Viewing 15 posts - 1 through 15 (of 25 total)