Never re-do the main query. Hook into pre_get_posts
and change it. The following needs to go in your functions.php
(putting in the template will mean it runs too late):
add_action( 'pre_get_posts', function ( $wp_query ) {
if ( $wp_query->is_main_query() && $wp_query->is_tag() ) {
$wp_query->set( 'posts_per_page', 20 );
$wp_query->set( 'post_type', [
'pavilion',
'post',
'catalog',
'tenders',
'services',
]);
}
});
And now your template code should just be:
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
// your code!
}
}
Related Posts:
- Is there a way to list all used/unused WP templates?
- How to create tag.php
- Creating a custom category page with pagination
- Any tag pagination page (except the 1st page) loads index.php template instead of tag.php
- How to remove wp_link_pages() from template
- Show all parts in multipage post
- Unable to display pagination links on custom category template
- Get URL of current post but not the page number
- How to get and set the post tag value within WP Query from URL?
- Query the database after get_header() has been included
- Unable to paginate a custom page query
- Dynamically generated URL and Content page
- Can index.php take over for front-page.php in template hierarchy on second page?
- which template does wp_ tag_ cloud point to?
- Pagination problem (plugin wp-pagenavi) with a custom post type?
- template with multiple post loops for multiple widgets [duplicate]
- How do I get tags linking to proper pages (/tag/sample-tag -> pages with that tag)
- How to add variables to a template
- Alternative layout the loop
- Editing the tag pages and using templates
- Is it possible to return a specific tag archive/template as one of the search results?
- Add pagination to blog
- Tag Posts showing in wrong places
- Any way to insert text on page from a query results?
- Custom template pagination
- How to use Class
in Java? - How to fix pagination for custom loops?
- Get name of the current template file
- How do you find out which template page is serving the current page?
- How to change the default registration email ? (plugin and/or non-plugin)
- Pagination not working with custom loop
- How do I get the size of an attachment file?
- Is there any way to use get_template_part() with folders?
- Adding Page Attributes Metabox and Page Templates to the Posts Edit Page?
- How can i change email template for new user
- Any advantage to using get_header() over include(‘header.php’)?
- Enable page templates. How?
- Is it possible to override the result of get_template_part()?
- Use [embed] filter in template files
- What’s the purpose of the paged.php file?
- How do you access the Product Short Description in a WooCommerce email template? [closed]
- Prevent comments_template() to load comments.php
- Page editor missing Templates drop down
- WordPress Paginate $wpdb->get_results
- Print WordPress template filename(s) for debugging
- How to force TinyMCE in WordPress to replace newlines with tags and not with
- How to find the posts page (home page) programatically
- WooCommerce: Change template for single product page
- View WordPress page template usage (or unused)
- How to edit contents of dynamic_sidebar()?
- How to check if a shortcode exists?
- Where is get_header(‘shop’) file in Woocommerce templates
- Custom templates folder
- tag.php doesn’t work with tags on a custom post type post?
- What is the link to my default “archive” page?
- How to get slug of current category in taxonomy template?
- How to show a under construction page for a domain but still be able to work on index.php?
- Change the name of the ‘Default Template’
- Customizing get_the_excerpt() to specific length and “Read More” output.
- How to Rename a Template File?
- get page templates
- How can I make wp-pagenavi work on a custom query built upon a form submission? [closed]
- Echoing Elementor page content in template, but it doesn’t get styles and some widgets are missing
- Using WordPress templating for HTML emails
- Loading partial templates with AJAX/PJAX
- Custom WP_Query order by post_meta and (author) user_meta
- WP frontend output of custom textarea fields not respecting line breaks. In admin it’s OK
- How do you check if a WordPress template file exist?
- Load entire NextGEN gallery from single thumbnail?
- I put my blog on a subpage, how do I get page title?
- A special single page templates for posts under a category and all its child category
- Executing Queries in tag.php
- Custom reset password template after forgot password request
- Outputting Canonical Resource URLs Across a Multisite Network?
- Gravity Forms Custom Templates [closed]
- Child Theme: how to override variables?
- Static Frontpage Pagination – Custom loop
- How do I get the URL of a specific size featured image?
- Where to store some per-template preferences?
- add/apend templates ‘transparently’ via plugin to currently active theme or child theme?
- stop blog page from using index.php?
- How can I modify the default reset (lost) password email text?
- Template files missing after moving site
- How do I override template-tags.php in twentyseventeen theme
- Get template part vs locate template function
- Programmatically change post templates?
- How to hide/redirect the author page
- Tools for Converting an Existing Website Design to a WordPress Template?
- Gutenberg & Pre-formatted Templates: Core Block Attributes
- Restrict a search to a custom post type
- Gutenberg Editor – Template Doesn’t Match Error
- author.php added to template not working on Nginx server
- Test if page is child and has children, if so echo child pages also on grandchild pages
- Need to give custom page template for each language in WPML
- roots child theme can’t override header.php
- Order posts by tags count?
- How did you incorporate WooCommerce in your own WordPress theme?
- Posts in Multiple Columns and Rows with one single loop
- How do I sort multiples pages?
- Add and in the header while looping over custom query in page template