is_tag()
is true for the entire tag archive page and for any queries that run on it. You need to restrict that code to only run for the main query on that page and that hte query is a tag query and not some other kind of query, like a menu query. You do that by checking the actual query object being used.
function myTagFilter($query) {
$post_type = $_GET['type'];
if ($query->is_main_query() && $query->is_tag()){
if (!$post_type) {
$post_type="any";
}
$query->set('post_type', $post_type);
}
return $query;
};
add_filter('pre_get_posts','myTagFilter');
is_tag()
, is_single()
, and other conditionals like that are functions that check the global
$wp_query
object. You have to be careful not to use them to check things that are not that global
object.
Related Posts:
- Remove “Category:”, “Tag:”, “Author:” from the_archive_title
- Order posts (across the whole site) by metadata date
- Get list of years when posts have been published
- Remove tag on my RSS Feed
- get_the_excerpt() not returning anything when post has no excerpt
- Automatically add author’s name to post_tag
- Adding a class to tag list in a function
- Create single.php for specific tag by tag id or name
- list tags with count in author profile page
- Product Tags in Add New product as checkbox list [closed]
- Retrieve tags data in post body
- Echo tags used to describe the theme
- Display posts from only one post form in custom query and exclude in main query
- How to set default archive image without overriding first attached image? [closed]
- Frontend tag edit/submit form
- Is possible add icon in title posts only in specific tag?
- Pagination in relation to archive.php
- Display tags that only appear in one category
- Add a unique class to HTML tag/element
- How to edit the Tags within the image file URLs?
- Tags break custom Excerpt function
- Numbering lines of code with the tag?
- Randomizing wp_tag_cloud() in child theme
- How to display the_archive_title() and the_archive_description() – “weird” interaction
- Image loading function not working on archive.php template
- Sort and display pages with specific custom field (not tag)
- Function to echo (or display?) wordpress tags in the head section
- Overwriting TwentyTwelve template file with child theme template, but lower in the hierarchy
- Simplest Way to Build Custom Archives Page?
- Create a CUstom Archive by Year, but just for a Single Category
- Exclude specific post from query
- What is wp_get_post_tags for media tags?
- Allow user only create specific tags
- Changing author links on homepage to buddypress profiles – without affecting ability to link to author archive throughout the site
- Removing sanitize_title_with_dashes Function with The Real Title
- Featured image on archive page based on post type
- method to fetch entire tag list on archive.php
- require_once() Causing categories and tag pages on dashboard to not refrsh
- Change post count on tag/terms pages to 10
- Replacing term/taxonomy archive pages with search queries
- Custom taxonomy not refreshing page on add
- Automatically add tag if a checkbox is checked
- getExcerpt: Make ellipsis appear only if character limit is reached
- Make WordPress search for only this tags or exclude certain tags from search [duplicate]
- How to get tags and categories?
- If two tags in the middle i need comma
- Display function from functions.php in tag.php
- Bulk set Post Title as Tag where Tag is Empty Function
- Programatically add options to “add new” custom field dropdown
- Excluding iPad from wp_is_mobile
- Use ‘add_theme_support’ instead of ‘add_custom_image_header’ In WordPress 3.4
- Replacing select2 in admin backend for all selects
- difference between add_object_page and add_menu_page
- How to hook into the quick edit action?
- I created a child theme and it doesn’t work for some of the css files
- How to programmatically set a menu to be the Primary Menu?
- Trying to inject twitter metadata into using wp_head action in functions.php – get_the_excerpt() returns null
- How to hide, and not to remove the attributes metabox?
- how to edit functions.php in a child theme
- Only display link to author social media when it exists [closed]
- Get current page_id before loop, in functions.php
- Menu fallback “menu_class” rendering a “div” instead of a “ul”
- Prepend or add an Image to the content of a Post
- Using $themename Variables
- How to add a slide toggle to the Woocommerce-Layout__Activity-Panel area in the orders admin page
- How to auto refresh when user change postcode
- Add sequential number to a Gravityforms form
- wp-comment author- url +, email filter hook
- how can I just add to parent theme function(s) instead of redeclaring whole the function
- Why does re-using this function not work? [closed]
- using jQuery on only one page
- Setting a default text for excerpts of a particular category
- How to use author meta in shortcode?
- How to rewrite wordpress search to work on specific category
- How to Add Shortcode to html img code?
- Logout Redirect and also WP-login.php Redirect
- Proper Way to Load stylesheet on Condition
- Custom Tags Archive – permalinks not working
- How do I place a function in a standalone page?
- Problem in using Customizer
- Conditional custom menu?
- What function actually renders the wp_admin_bar ? How can I call it?
- Do I Need to Prefix Variables Inside Functions?
- redirecting a URL if accessed directly
- Detect Ajax call inside pre_get_posts function
- Render page with specific id from functions.php
- Display Child Pages if no child Exists Display Siblings
- Filter works on last selection but no others
- WordPress does not load jQuery
- get_current_user_id() always return 0 in if else statement
- Menu and category highlighting for a single post
- I need to ‘wp_dequeue_script’ and ‘styles’ and ADD a bunch of other css and js
- True email confirmation for registration (keeping unvalidated users from user table)
- How to use if (is_page_template (”))
- wordpress function through ajax not being called
- Automatically add custom fields (post_meta) to all published posts, hourly, via wp_cron?
- How to mirror exactly the left admin menu on front end?
- update_post_meta after form is submited
- Make a table out of meta box
- function to show youtube videos within excerpt – if condition and apply_filters