Don’t run custom queries in the template to modify query parameters. The main query runs before the template is loaded, doing this is a waste of resources and introduces pagination issues, as you have discovered.
Remove your custom WP_Query
, restore the normal loop, and use pre_get_posts
to modify query parameters before the query is run.
function wpa_services_posts_per_page( $query ) {
if ( !is_admin()
&& $query->is_post_type_archive( 'services' )
&& $query->is_main_query() ) {
$query->set( 'posts_per_page', 5 );
}
}
add_action( 'pre_get_posts', 'wpa_services_posts_per_page' );
Related Posts:
- Paginated Taxonomy Term Archive including one post per term
- Pagination : How to remove /page/x/ after a ‘POST’ action on a form returning to page 1
- Pagination for Custom Taxonomy Page [duplicate]
- Custom taxonomy rewrite give pagination 404
- Custom post type and custom taxonomy 404 on page 2
- custom taxonomy pagination 404 error
- Display all posts in a custom post type, grouped by a custom taxonomy
- Exclude a category from WP_Query
- query multiple taxonomies
- Custom Taxonomy with Custom Post Type Finds No Posts
- Number of pages – multiple (custom) post types
- Custom query – alternate posts by category
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- Pagination Doesn’t Work
- how to group custom post type posts by custom taxonomy terms
- Numeric pagination custom post type
- Sort the main query in subcategories/terms?
- Custom Taxonomy List links being re-written
- Want to filter only parent post in admin area
- Pagination Issue: Custom Post Type In Index
- Custom post query by taxonomy
- Querying CPT with Two Taxonomies
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Custom Query to display posts with custom field
- Get taxonomy description based on variable
- Order WordPress Custom Taxonomy Pages & Pagination Not Working
- Unable to get paginate_links working with a custom query [duplicate]
- Group custom posts by custom taxonomy names
- How can i skip same post from taxonomy term?
- Filter by custom taxonomy slug on a custom post type
- Pagination on a custom post type loop
- wp_query check if integer exists in custom field’s array
- Wrong request query on cpt and tax
- Previous/Next Link by Meta Value in CPT
- Search / Filter posts on Title/Content OR Tags
- Custom-Posttype & Custom Taxonomy WP_Query
- Custom loop with multiple taxonomy queries
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- What’s the WP way to load remaining custom posts?
- How do you paginate a query grouped by month?
- How to have this permalink structure: post_type/postname/custom_inner_page
- Query Custom Post Type Taxonomy term with multiple parameters
- Querying Custom Post Type, ordering by Custom Taxonomy Pagination Not Working
- Pagination with custom query, custom search form, single and pages, ajax and no plugins
- pagination not working for category.php (custom post types in categories)
- Retrieve custom post types by custom taxonomies with WP_Query
- Custom Taxonomy Not Showing in Front-End When Outputting a Custom Post Type with WP_Query()
- Pagination Not Working for Custom Taxonomy with Custom Query – 404 Error
- Can’t use pagination with custom taxonomy
- Using page slug in wp_query
- Custom taxonomy wp_query woes.
- Creating two loops based on different logic
- Trouble with pagination
- WP_Query parameter conflict
- previous_post_link in same taxonomy in custom post type
- Different options per post type in WP_Query
- How to show all taxonomies within custom post type loop
- Custom Category Walker with Image, Fallback to Most Recent Post in Category Image
- How to list custom post types on a custom post type page?
- How to query Posts from a custom post type which contains a custom taxonomy?
- Query Posts that have Custom Taxonomy
- List all Custom Post Type posts excluding certain Taxnomy term
- Foreach loop returning more than one item when querying taxonomy
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- Single parent post lists child posts with pagination
- Custom post type pagination error
- Sorting the Loop by Taxonomy Value
- Previous / Next Links For Custom Post Type Sorted By Meta_Value
- Custom archive page for custom taxonomy and pagination issue
- Ordering by meta value not working
- Display post count for a specific month
- Pagination Not Working When Used With WP_Query() `offset` Property
- pagination problem listing custom post types of taxonomy in wordpress
- WP_Query for custom taxonomies showing posts from non-specified terms?
- How to display custom post type pagination buttons when processing AJAX request
- Live search by custom tag
- Make pagination work as a carousel (custom query)
- Query a custom taxonomy in a function to create an csv file
- Why is my loop not populating the page with my custom taxonomy terms from my custom post type?
- Pagination with a custom post type
- I want to create pagination for my custom post type archive that i am displaying with loop
- Displaying WordPress posts from post and custom post type in custom taxonomy
- Display all Custom taxonomy terms and their relevant custom posts
- CPT Efficient way to display posts from different categories with custom query
- Get posts associated with custom taxonomy alternate way
- Loop with Custom Post Type and Taxonomies
- Pagination fault in custom post type archive page [duplicate]
- tax_query showing no results
- Values inside a custom field to determine which category posts to display
- Custom post type blog pagination conflict
- Custom post type pagination, single page issue
- Pagination for a Custom Taxonomy
- How to display elements of different post types?
- Pagination always adding “Next” link when results come from Custom Post Type WP_query
- Pagination not working on homepage
- Archive page – problem with pagination
- Attaching multiple custom taxonomies to one CPT?
- Get X posts with the same terms as the current post (custom post type and custom taxonomy)
- Query custom post type and group by taxonomy
- Dynamically count the number of custom post types associated to a custom taxonomy