Support

Home Forums Event Espresso Premium Using DTT_EVT_start as orderby parameter for Essential Grid

Using DTT_EVT_start as orderby parameter for Essential Grid

Posted: October 31, 2017 at 7:52 am

Viewing 11 reply threads


txhomedecor

October 31, 2017 at 7:52 am

Hi,

I’m trying to display the next 4 upcoming events on our homepage using Essential Grid, but the only way to get it to work successfully is with this parameter which calls them out individually:
post__in=array(1921,1887,1905,1977).

The problem here is we need to update it manually. Ideally I want to add these parameters and it seems it should work, however it doesn’t and seemingly pulls random events

orderby=Datetime.DTT_EVT_start&order=asc

I’ve been running the below code to try and find the proper parameter calls and when you look at the results it seems to be working, but the next 4 upcoming events are not being displayed. Any thoughts on how to accomplish this?

in child theme’s function.php:

add_filter('essgrid_get_posts', 'eg_mod_grid', 10, 2);
function eg_mod_grid($query, $grid_id){
    if($grid_id == '1'){
       //modify $query to your needs
       echo '<pre>'; print_r($query); echo '</pre>';
       //want to update parameters or modify query here to get next 4 upcoming events from today on...
    }

    return $query;
}

Results:
Array
(
    [order] => asc
    [posts_per_page] => 4
    [showposts] => 4
    [post_status] => publish
    [post_type] => espresso_events
    [orderby] => <strong>Datetime.DTT_EVT_start</strong>
    [tax_query] => Array
        (
            [0] => Array
                (
                    [taxonomy] => espresso_event_categories
                    [field] => id
                    [terms] => Array
                        (
                            [0] => 12
                        )

                )

            [relation] => OR
        )

    [suppress_filters] => 
)
  • This topic was modified 6 years, 11 months ago by Tony. Reason: Code formatting


Tony

  • Support Staff

October 31, 2017 at 3:47 pm

Hi there,

Essential grid will just be using WP_Query, which won’t know what ‘Datetime.DTT_EVT_start’ is.

Can you send me a copy of the plugin so I can take a look? If so you’ll need to host the zip file somewhere (Dropbox for example) and post a link we can use to download it.


txhomedecor

November 1, 2017 at 10:14 am

Thanks Tony. I will let you know when I get it on a drive for you.


txhomedecor

November 1, 2017 at 1:14 pm

Tony, I can’t upload the file from work due to restrictions, but this is the website for the app: https://essential.themepunch.com/. i’ll try to get the app up there this evening.


txhomedecor

November 1, 2017 at 1:36 pm

I’ve played a little more and got the following to function, however the start dates are still not showing. This is based on another topic that says it works using start_date:
https://eventespresso.com/topic/using-ee_event_list_query-to-sort-events-by-start-date-instead-of-post-date/

You can see the below in action at https://www.designandmine.com/ The echo text is right above the pictures in Upcoming Events and can be highlighted as they are purposefully hard to see.


add_filter('essgrid_get_posts', 'eg_mod_grid', 10, 2);
function eg_mod_grid($query, $grid_id){
    if($grid_id == '1'){
       //modify $query to your needs
       //$query-> set('orderby' ,'start_date');
       //echo '<pre>'; print_r($query); echo '</pre>';
       //to see what the query actually really looks like
    }
     
    $posts_array = espresso_get_events(array(
        'limit' => 4,
        'order_by' => 'start_date',
        //'order_by' => 'DTT_EVT_start',
        'show_expired' => FALSE,
        'sort' => 'ASC',
    ));

    // array to use for results
    $months = array();
	$date_format = get_option( 'date_format' );
  	$time_format = get_option( 'time_format' );
    if(!empty($posts_array)){
        foreach($posts_array as $post){
			//echo ' ' . $post->post_title . ' ';
            //echo ' date: ' . $post->DTT_EVT_start . ' ';
            $datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $eventPost->ID, false, false, 1 );
      		foreach ( $datetimes as $datetime ):
        		$months[date('F Y', strtotime( $datetime->start_date() ))][] = $eventPost;
      		endforeach;
            echo ' date: ' . $post->start_date . ' ';
            //echo ' ' . $post->DTT_description . ' ';
            echo ' date: ' . $months . ' ';
        }
    }  
    return $query;


txhomedecor

November 1, 2017 at 8:44 pm

Tony,

Here is the link to the app for you to install:
Ess Grid


Tony

  • Support Staff

November 2, 2017 at 6:18 am

There’s a lot wrong with the code your using above.

$date_format and $time_format aren’t used or needed.

$eventPost doesn’t exists but you’re trying to use it in a couple of locations (it should be $post).

$months is an array and you can’t echo out an array.

One problem your going to run into with this testing is that you are using the built in EE functions to query the events, the EE functions take car of all of the joins within the query for you, so the query_args you pass to those functions will not work with a pure wp_query call (which Essential grid uses). SO even if you pull the correct events with your query, and then pass the same args to essential grids query, it wouldn’t work.

For that query to work you’ll need to add the joins that EE does for you and then set the orderby (and I’d advise adding a group by post.ID) take a look here:

https://gist.github.com/Pebblo/46702059755a1ba5b30d2b447e6c413e


txhomedecor

November 2, 2017 at 6:43 am

Thanks Tony. As you can see, i’ve pieced this together from many different sources, with this one being the initial source https://eventespresso.com/topic/using-ee_event_list_query-to-sort-events-by-start-date-instead-of-post-date/

I’ll take a look at the gist you mentioned and work from there.

But honestly, i’m not sure why I need to do any custom code at all as i’m just trying to display the next 4 upcoming events in a essential grid.

If there’s a better grid tool that can be used to work with event espresso, please let me know 🙂

Thanks again for the help.


Tony

  • Support Staff

November 2, 2017 at 6:48 am

Yeah, I can see you’ve pieced it together, but it won’t work with how you have it now. With WP_DEBUG enabled you’ll get all kinds of notices of undefined variables.

But honestly, i’m not sure why I need to do any custom code at all as i’m just trying to display the next 4 upcoming events in a essential grid.

There’s only so much we can do to integrate with various different plugins, but as long as the query is filtered its usually possible to get the details needed (as it is with the above).

Adding the above snippet I provided should just work how you expecting without any other custom code.

If there’s a better grid tool that can be used to work with event espresso, please let me know

EE has its own grid tool – https://eventespresso.com/product/eea-events-grid-view-template/

It doesn’t have all of the features essential grid does, so I can’t say its better, but it does pull the EE events without custom code 😉


txhomedecor

November 2, 2017 at 7:51 am

The link you sent is working much better and I can see how the EE works with WP now
https://gist.github.com/Pebblo/46702059755a1ba5b30d2b447e6c413e

It’s still not 100% as it is skipping some events. I think it’s related to the group by post id since the events aren’t always entered in perfect date order. So you can have a higher post number that takes place before the post right before it. But the code you referred me to was a great help!

I’ll also look into the EE grid tool as well.

There’s only so much we can do to integrate with various different plugins, but as long as the query is filtered its usually possible to get the details needed (as it is with the above).

Completely understood. We didn’t initially create the site, but were made to believe that Ess Grid and EE were chosen since they already were integrated 🙂 Not a knock on EE, just what we had been led to believe.

Thanks again for the help!


txhomedecor

November 2, 2017 at 8:28 am

FYI, it was not related to the post id. some of the events entered didn’t have the proper category assigned and were excluded from the query. So the code is working completely as expected!

Putting the link here for future developers, but same as what you posted earlier.
https://gist.github.com/Pebblo/46702059755a1ba5b30d2b447e6c413e

Thanks Tony!


Tony

  • Support Staff

November 2, 2017 at 8:39 am

Great, I’m glad it’s working.

Just to give some info of the group by post.id, when a single event has multiple datetimes within it the query will pull multiple of the same post because the dateime event ids match the post id. As they are all the same event the group by just makes sure one post is pulled.

Viewing 11 reply threads

The support post ‘Using DTT_EVT_start as orderby parameter for Essential Grid’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso