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
- Missing feature image link function
- What’s the difference between home_url() and site_url()
- get_template_directory_uri pointing to parent theme not child theme
- How to customize the_archive_title()?
- remove empty paragraphs from the_content?
- What is the “with_front” rewrite key?
- Why use if function_exists?
- How to override parent functions in child themes?
- wp_enqueue_script was called incorrectly
- Add multiple custom fields to the general settings page
- Ajax call always returns 0
- 400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook
- How long does a deprecated function live in core?
- Solution to render Shortcodes in Admin Editor
- How to add a data attribute to a WordPress menu item
- What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
- remove_action on after_setup_theme not working from child theme
- plugins_url vs plugin_dir_url
- Remove type attribute from script and style tags added by WordPress
- How to run a function every 5 minutes?
- Best way of passing PHP variable between partials?
- Upload Multiple Files With media_handle_upload
- How to display custom field in woocommerce orders in admin panel?
- Adding fields to the “Add New User” screen in the dashboard
- Issues with title-tag and document_title_parts
- How do I get the current edit page ID in the admin?
- How to check if a user exists by a given id
- Why isn’t is_page working when I put it in the functions.php file?
- Add tags to the section via functions.php
- Add image size if page template
- How to create a custom order status in woocommerce!
- Remove Actions/Filters added via Anonymous Functions
- Adding a second email address to a completed order in WooCommerce [closed]
- How to load parent_theme functions.php before child_theme?
- How to load scripts/styles specific for a page
- Programatically add options to “add new” custom field dropdown
- Is there any global functions.php file which works for any theme?
- Excluding iPad from wp_is_mobile
- When should you, and when should you not, use wp_list_pluck()?
- Get the ID of the page a menu item links to?
- Add container to nav_menu sub menu
- Difference between the_permalink() and get_permalink() function
- What’s the difference between WordPress random_int() and PHP built-in function random_int()?
- Child theme – Overriding ‘require_once’ in functions.php
- How to not allow users to create new tags, but allow to them to use existing ones
- Link to user’s profile settings page?
- WordPress Enqueue for homepage only, functions.php, wp-framework
- get php variable from functions php and echo it in theme template files [closed]
- Get menu object from theme_location
- Is it ok to use a function to output the text domain name in a wordpress theme
- Displaying the number of updates available in the Admin area
- Trying to use add_action and do_action with parameters