Your code has a couple of flaws which I’m not going to go into detail now. Here is a short list
-
pre_get_posts
is an action -
On any type of archive page you need to make sure you only target the main query and the front end when using
pre_get_posts
-
Your syntax is very hard to debug and not supported by most code editors. Although
if (): else : endif;
is valid php, it is not recommended due the trouble debugging it. Use proper curlies likeif () { } else { }
-
Most of your code does not make much sense. Please see my code and compare it with yours
You can rewrite your code as follows
add_action( 'pre_get_posts', function ( $q )
{
if ( !is_admin() // Make sure you only target the front end
&& $q->is_main_query() // Only target the main query
&& $q->is_tag() // Only target the tag pages
) {
$q->set( 'post_type', array( 'post', 'btp_work' ) ); // Change as necessary
}
});
Related Posts:
- Find callback function for custom taxonomy metabox
- Exclude Custom Post Type & Pages From Auto-Tag Function
- display custom portfolio tags
- CPT tags not showing when editing post
- How to convert Post Object Custom Field into Tags
- Redeclare/Change Slug of a Plugin’s Custom Post Type
- Sort search results by post type
- Taxonomy count per Post type
- post_tag taxonomy with custom post type
- How do I add a custom post type to the Featured Content in twenty fourteen theme?
- Saving multiple Metabox contents
- Is it possible to insert text into an html tag using functions.php?
- Custom post type loops with different page templates
- Multiple Content Block
- Unable to save or update postmeta for custom post type via action using save_post hook
- Registering tags taxonomy for a custom post type
- Categories and Tags not working!
- How to: add option to add more checkboxes on custom post type
- Allow Users Access to Custom Post Type Only
- How do you output custom code between posts in the loop?
- How to get Custom Post ID by adding filter to child theme’s function
- Output custom post shortcode. Help spot the error.
- When ‘is_post_type_archive()’ return true?
- How to add the post ID (or any other post data) to a Contact Form 7 mail?
- How To Enable Block Editor (Gutenberg) for Existing Post Type via functions.php
- Where to store custom tagging data associated with a custom post type
- Modifying Custom Post Type after registration (will it affect content?)
- Can custom taxonomies items have attached properties?
- Create a post in custom post type using field in registration form after users submit form
- A good strategy to print custom posts (offer) that are checked inside the metabox of a post?
- right_now_content_table_end function not working?
- Does anyone have a plugin that could automatically tag custom post types in wordpress?
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- Custom post types and tag archive pages/permalink structure issue
- Tag Archive for Custom-Post-Type Posts yielding 404 when permalinks set to postname
- Listing tags from a custom post type
- wp_update_term_count_now doesn’t work with a custom post type?
- How to target a specific custom post type post and its all children and grandchildren?
- ACF field key/value to show on taxonomy list
- Re-registering a custom post type not working (not showing up)
- How to make custom posts types display when published for the future
- CPT archive admin menu label
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Cross reference custom post types
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Add term to custom post type on draft
- How can I show 1 featured post in a styled element, and the next few below differently styled
- Template not working for the custom Post type
- Show all tags on custom post type
- Loop increase number
- ACF in wordpress
- Change Slug of a Custom Post Type
- get_the_tag_list() returns bad links
- List of all entries of custom-post-type: Add year-parameter?
- How can I create an automatic drop down menu with my tags?
- display custom taxonomies limited to custom post type?
- How to inherit field value from parent post into in child / sub post
- WordPress admin display post type tags as checkbox
- The Difference Between Categories and Tags and Taxonomies and Terms
- Custom post type’s posts are not showing anywere but in xml sitemap
- Removing full title and breadcrumb header container for a specific post type
- Show current user posts in custom post type query
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- How to constrain the results to a specific post_type on tag archive page?
- Custom post type in Custom widget – $listItem
- add custom tags for custom post type in wordpress
- Meta box not appearing in my custom post type
- Function to erase every post from a taxonomy
- Redirect to URL if x number of days passed
- Display author box on just certain category posts?
- Custom post type, taxonomy and admin bar
- Tag template not returning posts [closed]
- Why doesnt my tag page populate with this custom post type?
- redirect after submiting post for review
- How to divide Subcategories into pages of parent category wordpress
- how to achieve this permalink abc.com/CPTName/CustomPostTypeCategorySlug/categoryname
- Create WordPress User in backend, and automatically create a new post in Custom Post Type with user uame as the Title in the post
- update custom taxonomy custom fields
- Different number posts per page based on custom post type term id
- how to display author name in custom post type
- How to get current post type?
- Create dynamic logo carousel without using any plugin
- fusion builder missing from custom post editor
- Stored meta from attachment, video length?
- Duplicate posts in my custom loop
- Featured image in custom post is being disabled
- custom post type does not working when adding in child theme function
- call_user_func_array() error after moving to another server
- Organizing The Custom Post Type with Taxonomies / Parent Posts
- Default taxonomy ‘post_tag’ added to CPT managing by custom role : nothing in the metabox
- Updating User Meta from Custom Post Field Upon Publish Not Working
- I want to split this into two functions
- Generate daily archive whenever any post type is added
- Invalid Taxonomy in template
- Custom post type functions.php if statement on action
- Add HTML before a specific div?
- Custom Post Types using wrong template (index) instead of archive-{type}.php – previously worked as expected
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- I want to show a list of posts under specified categories
- Is it possible to use a post name in a custom post slug?