pre_get_posts is executed before each and every query. Your $query->is_main_query() is making this code change the query only for the Main query. So, if you’re in an archive page, you’re modifying only the archive posts, and not any of the others queries (widgets, menus, etc).
But be aware, that code you added there will change the query for ALL your main queries. So if you go to another post type archives (categories, etc) you will be modifying the query to get the post_type = employee
Related Posts:
- Most commented last 24h, week, month, year and all time – posts_where
- All Posts Have The Same Comments
- How to add a recent post function to a text widget I created for practice?
- When to use WP_query(), query_posts() and pre_get_posts
- Should I use Pre Get Posts or WP_Query
- Using pre_get_posts with WP_Query
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- What is “main query”? [duplicate]
- WP_Comment_Query pagination, delving into the unknown
- Reduce or prevent calling of update_meta_cache
- How to add taxonomy filter on the query fly?
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- How to uniquely identify queries?
- Order Search Results Page by meta_value If no Value Return Remaining Results
- pre_get_posts with get_posts
- How-to exclude terms from the main query the most performant way?
- Exclude comments from a WP_Query object?
- Changing Posts Per Page and offset with pre_get_posts
- Slow SQL_CALC_FOUND_ROWS Query
- “pre_get_posts” firing on every query
- RSS feed with specific keyword
- Using is_main_query to select custom post type on certain page
- Multiple orderby parameters in pre_get_posts() action
- Get posts with condition on comment meta value
- WP_Query sort by comment meta data
- SQL Statement generated by WP_Query not producing expected results
- Add inline HTML to posts published within last 24hrs
- Sorting Posts by custom field
- How to pass custom parameter to WP_Query for filtering in pre_get_posts
- Query with pre_get_posts to get pagination
- Recommended way to drop a pending query (in pre_get_posts)?
- meta_query not working properly
- Single page theme that uses pages for the content
- Get number of comments after modifying comment query
- WordPress custom search form with pre_get_posts not work
- If orderby parameter using pre_get_posts is the same for multiple posts what fallback does the query use?
- Can not switch the queried post in pre_get_posts hook
- using wp_query to return posts w/ comment count > 0
- Show one post per author and limit query to 8 posts
- order by multiple meta keys in pre_get_posts
- How to sort posts in admin by titles with dd.mm.yyyy format?
- Pass the same object to multiple widgets in a template with one query
- How can i make WP_Query return post image and categories?
- WP_Tax_Query with post_tag not working
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- How to Modify Taxonomy Archive Page with Search Parameter?
- Query posts with more than 20 comments
- Order posts by meta value and Date
- Using pre_get_posts on a specific core/query block
- Searching through different categories on different pages code is not working
- How to display future posts – modified query still yields 404
- pre_get_posts filter meta_query without conflicting existing meta_query
- Including only current user’s posts in search
- When querying a combination of posts and other meta fields, is there a better solution than directly modifying the WHERE value?
- How to change posts order on Category and Tag archives?
- How can I retrieve comments from last 5 minutes for a post?
- How to get most recent commented post above new submitted post in WordPress?
- Retrieving list of a custom post type in a widget without using WP_Query?
- Sorting posts DESC based on the number of comments using WP_Query
- Formulate a url to show posts with both taxonomy terms
- My Main Query Modification is Messing up my dynamic main – why?
- Offset Page Loops and Pagination
- pre_get_posts Remove tax_query Completely
- pre_get_posts order by not working
- Adding a parameter to the default query
- Using WP_Query in “parse_query” or “pre_get_post” in Posts2Posts
- Single meta_query query using OR instead of AND in request’s WHERE statement
- How to choose between hooking into per_get_posts or into parse_query
- Store sticky post’s ids in a transient
- How to change main query based on post meta
- new WP_Query to get max price meta value not working
- Display posts from only one post form in custom query and exclude in main query
- Show Sticky Post at the top but do not show again in the loop?
- WP_Query, pre_get_posts and offset
- Complex WP SQL Query
- How to detect if query is runned from widget?
- Using meta_query with multiple keys and compare values
- Can I set my WP_Query to be a Main Query?
- Remove category from query (show all posts in archive.php) pre_get_posts()
- Show scheduled posts in main loop but not in WP_Query?
- Most commented post showing 2 records
- WordPress Comments sort by custom meta key
- Show post number in widget loop
- hide custom post types with specific meta key ON admin backend
- WP_Query ignoring tax_query when is_singular
- Applying posts_clauses filter to specific queries only
- Help ordering Post loop by two meta values
- Filtering out child category posts from parent category archive not working
- Order ascending is ignored in meta query?
- New WP_Query calls Pre_get_posts filter twice
- Query posts by last comments
- How to list posts with disabled/closed comments, with pagination?
- WP_Query with offset and ‘orderby’ => ‘rand’, offset not working
- Shouldn’t I be able to modify the main query by this filter?
- How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?
- using pre_get_posts for search results not found
- Hide elements outside loop based on query
- Reset WordPress Post Query to default
- Woocommerce – exclude only older out-of-stock items
- WP Query – order posts by meta field first and then order the rest