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? - Pagination not working with custom loop
- Is there any way to use get_template_part() with folders?
- How to edit contents of dynamic_sidebar()?
- Loading partial templates with AJAX/PJAX
- A special single page templates for posts under a category and all its child category
- Where to store some per-template preferences?
- How do I override template-tags.php in twentyseventeen theme
- roots child theme can’t override header.php
- How do I sort multiples pages?
- Transient pagination not working properly
- Which has more impact on site performance? Template overrides or hooks
- Pagination problem after WP_Query with tag filtering
- Advanced Custom Fields – display when specific template used?
- What should I put on my index.php?
- How To Create WooCommerce Custom Template For Specific Product?
- How to Use Twig + Timber with Multiple Loops based on Meta Key Value
- Missing .twig files in wordpress theme editor
- How to custom page template for the Gutenberg editor
- Use PHP templates as blocks
- Directly using pure JWPlayer JS (but NOT WP Plugin)
- Login page theming?
- WordPress 3.2 query_posts and pagination, permalinks issue
- I want to add a custom “all posts by author” by authors name. How?
- Advanced templating / WordPress as a CMS questions
- I can ‘t display product images based on the label
- Query posts intersecting tags and categories
- displaying category and subject posts
- How to duplicate a page template but make minor changes to the header?
- get_template_directory() still returning path to previous theme
- URL / Templating system advice [closed]
- What’s the purpose of $wp_did_header?
- Is there a way to by-pass the pagination function on one custom template?
- Unable to add template to page set as Posts page in WP V 4.6.1
- Dynamically Insert Image Into Stylesheet
- How to access .html file that’s located in the theme folder from the browser?
- Why won’t pagination work?
- Way to use one template but be able to call different top graphics?
- Differnt page template for page 2 of blog feed
- Create template for just a print
- dynamic_sidebar() stopped working
- WP overwrites my setup_postdata() setup
- get posts by tag to showing in a widget
- Customizing the_tags output?
- Removing calls to noindex() and wp_no_robots()
- Does wp_mail work in frontend tempate file?
- Organize template parts and page templates in folders in regards of template hierarchy
- Tag template not returning posts [closed]
- Getting a WordPress tag to print inside of a traditional php echo
- wordpress – modifying template to show more posts
- How to get all template files used for rendering a single post/page?
- how to add tags to post in the Loop?
- Pagination of custom page with custom fields query
- Home page not loading after editing header.php file
- Template includes
- Fixing media query
- Set og:image programmatically in custom single post with external images
- Displaying all posts of a category in full view on one page using their single.php template
- why does not showing my custom post category list in any template?
- Locating the HTML piece of code in wordpress
- Theme keeps going to default files [closed]
- How can I show contents of a template part inside of another page?
- How to serve a amp template
- Single page applications with WordPress: routes and templates
- Display different list of “Custom Templates” for each Custom Page Type
- Submit form to another template (ugly url)
- Using file outside of template hierarchy for Twitter sign in authentication
- List all pages using a specific template on a page
- Duplicated Template Does Not Load the Same as the Original Template File?
- Pagination not working with custom loop
- How do I add tags/taxonomy to images + a query field on page to query ‘albums’ (images with same tag/taxonomy)
- Blog template PHP [closed]
- load_textdomain won’t load my .mo file
- html blog template to wordpress template
- Can I create my own query in wordpress with traditional methods?