Support

Home Forums Event Espresso Premium Getting all Events to show on custom admin listings page

Getting all Events to show on custom admin listings page

Posted: February 18, 2016 at 5:46 am

Viewing 3 reply threads


Linda Isarasakdi

February 18, 2016 at 5:46 am

Your support staff kindly supplied a function in this thread which creates a separate admin page for listing events and making it possible to use Admin Columns to control those listings.

I’ve been trying to figure out how to make all events display on that admin screen. It’s only showing ones with the status of Active.

At the top of the screen, the ALL and PUBLISHED status links are at 68, but we’re only seeing 31. I was trying to set pre_get_posts a publish status of ANY, but suspect I’m not targeting this admin screen properly.


Linda Isarasakdi

February 18, 2016 at 5:48 am

Sorry, forgot the code

function allow_all_event_statuses( $query ) {
	//$screen = get_current_screen();  Sadly this page is one of those that does not support get_current_screen
	global $pagenow;
    if( is_admin() && 'edit.php' == $pagenow && $query->query['post_type'] == 'espresso_events' ) {
		$query->set( 'post_status', 'any' );
	}

}
add_action( 'pre_get_posts', 'allow_all_event_statuses' );


Josh

  • Support Staff

February 18, 2016 at 12:19 pm

Hi Linda,

That could be and it could also could be the hook point. However, you do not need to alter the post_status part of the query. That’s not the reason you’re seeing all of the events. I encourage you to set up the debug bar plugin so you can see the actual query on that page. You install the debug bar plugin, and set this in the wp-config.php:

define( 'SAVEQUERIES', true );

Then, you click the debug bar and click WP Query to see the last query. You’ll note that the post statuses are included in the query, and the part that’s limiting the events is there’s a where clause that checks the end dates for event’s datetimes.

The query actually filters the default list and so it only displays events where their last end dates are after the current date and time. It’s actually something that Event Espresso adds via the posts_where filter. So you can do something like this to remove that filter:

I also recommend installing the Debug bar’s action and filter hooks plugin. This makes for quick and easy finding of the hooks like the one above.


Linda Isarasakdi

February 19, 2016 at 1:04 am

Josh, you’re a life-saver. Of course I should have been using debug to see what was affecting the query!

Only thing I had to change was the get_current_screen. It was throwing an undefined function error. Here’s what’s working for me:

`add_action( ‘pre_get_posts’, ‘ee_view_all_events_table’, 11 );
function ee_view_all_events_table($query) {
global $pagenow;
if ( is_admin() && ‘edit.php’ == $pagenow && $query->query[‘post_type’] == ‘espresso_events’ ) {
$CPT_Event_Strategy = EE_Registry::instance()->load_core( ‘EE_CPT_Event_Strategy’ );
remove_filter( ‘posts_where’, array( $CPT_Event_Strategy, ‘posts_where’ ), 10 );
}
}’

Thanks again!!!

Viewing 3 reply threads

The support post ‘Getting all Events to show on custom admin listings page’ 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