Custom posts affecting Recent Posts

I don’t really understand your question, but I see a couple of issues that might have a negative effect on other queries

Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with posts pagination).

  • Always use WP_Query or get_posts to create custom queries if you can’t alter the main query with pre_get_posts to suite your needs.

  • The most probable cause for interference with other queries is the fact that you did not reset your custom query. This is very important as any custom query that has not been reset will have a negative effect on any other query on the same page. You can reset your query with wp_reset_postdata() just after your custom query

For extra info, go an read this post I have recently done

EDIT

This seems, from your comments, that the problem is not related to the code in question

…I’ve now changed the plugin to use wp_query and added wp_reset_postdata() but the problem persists

You need to debug this, and I would look for the following

  • Any instance of pre_get_posts. One thing to remember when using pre_get_posts, it alters all queries, main and custom, if not properly used. Make sure that each instance, if it should target only the main query, that the following code is in there if( $query->is_main_query())

  • Are you maybe running a custom query in place of the main query on your category page. if so, don’t do that. Please read this post which will explain everything.

  • Also, turn on debugging and check if you get any errors. Try switching to a bundled theme and deactivate all other plugins and check if your problem is related to your plugin or to the theme you are using. If you get the same issue after switching themes, it is most probably your plugin

EDIT 2

As I suspected, it is an instance of pre_get_posts that is the culprit of the problem. Have a look at the following lines in quick-event-manager.php

Line 28: add_filter( 'pre_get_posts', 'qem_add_custom_types' );

Line 106: function qem_add_custom_types( $query ) {
Line 107:     if( is_category() || is_tag() ) {
Line 108:                   $query->set( 'post_type', array('post', 'event','nav_menu_item'));
Line 109:             return $query;
Line 110:      }
Line 111: } 

pre_get_posts don’t just changes the main query, it also changes custom queries. This also don’t just happens on the front end, but also in the back end. So you need to be very careful when using pre_get_posts , otherwise you’ll end up with the problem you are having

LETS DISSECT WHAT IS HAPPENING

The recent post widget uses a custom query to display the recent posts in the sidebar. What your code is doing, it adds the following post types to all queries when you are on either a category or tag page 'post', 'event','nav_menu_item'.

As I said, pre_get_posts acts on all queries, main and custom. That is why you see the weird behavior when on the category page, and actually, if you check, you’ll have the same problem on tag pages as well. Also, you should also see weird behavior in the back end when visiting the category and tag pages.

THE SOLUTION

ALWAYS when using pre_get_posts, direct it only to the main query (is_main_query()), and secondly, always check if you are on an admin page (back end) or front end page, and make changes to front end only (!is_admin())

You should change your code to

function qem_add_custom_types( $query ) {
    if( !is_admin() && $query->is_category() || $query->is_tag() && $query->is_main_query() ) {
            $query->set( 'post_type', array('post', 'event','nav_menu_item'));
        return $query;
        }
    }

This should take care of this problem.