Skip to content
Advertisement

Impossible to display list of *past* or *all* events (events manager plugin) in WP BACKEND with self-created theme

Sorry, this problem needs a longer description and I don’t really have any code to post (or rather, I wouldn’t know what code to post – see below)…

I have two websites with two self-created themes in which I use the Events Manager plugin. These themes are very similar concerning HTML structures, php code and javascripts, they differ mainly layout-wise, i.e. the CSS ist quite different. Both themes work without problems in the frontend.

However, in the BACKEND/dashboard there is a problem with Events Manager’s listing of events that only happens when using (let’s call it) Theme A: When (in the select menu above the list of events) I choose to display “past events” or “all events” (or actually any other option from that menu except the default “future events”), the result is an empty list of events with a note “no events found”.

At the top of that page the following note appears: Notice: Array to string conversion in /Applications/MAMP/htdocs/mywebsite/wp-admin/edit.php on line 329 (which apparently refers to a variable named $post_type). And directly above the list all select menus and buttons except the “Filter selection” button disappear (sorry, I am not sure about the English text of that button since I am on a German system where that button is labeled “Auswahl einschränken”).

What I did to check/debug:

  • I disabled all plugins (except Events Manager) – still the same behaviour
  • I switched Website A to other themes – the behaviour disappeared.
  • I copied Theme A to Website B (on the same server) and selected it there: Same behaviour, although when using (the very similar) Theme B in Website B the problem does not occur.
  • I disabled almost all of the different functions in the functions.php file one by one: no difference. -I switched to a different PHP version (7.4.12 to 8.0): no luck.

So the problem apparently really is caused by the theme. But in which way can a theme affect the backend display? – I definitely didn’t add anything to the theme to modify the backend. Compared to commercial themes that theme is very simple. And as I wrote: That theme (A) is almost identical to my Theme B, where this problem does not occur.

Does anyone have an idea what (in a theme) could cause this behaviour? I am really stuck here and appreciate any feedback!

Advertisement

Answer

I found the solution myself.

Posting all theme code (or even the complete code of the functions.php file) in the question would have been too much, but the problem was in there. I had the following function to limit search results to three particular post types (I have more than those in that website):

add_filter( 'pre_get_posts', 'limit_post_types_in_search' );
function limit_post_types_in_search( $query ) {
    if ( $query->is_search ) {
            $query->set( 'post_type', array('page', 'post', 'publication') );
    }
    return $query;
}

So, as @CBroe also mentioned in their comment, the search query is also used in the admin pages (dashboard) to filter lists by certain conditions, and since the “event” post type of the Events Manager plugin isn’t included in that function, there wouldn’t be any results. I could add it to that array to make it work, but for a certain reason I don’t want those events to show up in search results.

What fixed it was to include ! is_admin() as a condition in that function, to prevent it from being applied in the backend. So the complete modified code is as follows:

add_filter( 'pre_get_posts', 'limit_post_types_in_search' );
function limit_post_types_in_search( $query ) {
    if ( ! is_admin() && $query->is_search ) {
            $query->set( 'post_type', array('page', 'post', 'publication') );
    }
    return $query;
}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement