As this is your main loop of your template, you should not be making a new loop, but modify the existing loop with pre_get_posts
. This way you can be sure that all extra query parameters will be taken into account.
An example of how you would do this:
add_action( 'pre_get_posts', 'wpse5477_pre_get_posts' );
function wpse5477_pre_get_posts( $query )
{
if ( ! $query->is_main_query() || $query->is_admin() )
return false;
if ( $query->is_category() ) {
$query->set( 'post_type', 'video' );
$query->set( 'posts_per_page', 6 );
}
return $query;
}
This code will go in your functions.php
.
First we check if this is the main loop and not your admin area. pre_get_posts
can affect admin.
Then, if this is a category, we modify the $query
.
And then return the $query
.
For more information check here: https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
Related Posts:
- Custom Post Type, Two categories, Two columns with Pagination
- Pagination on category page with custom post types
- Category with post type pagination returns 404
- WordPress custom post type post and category links 404
- What Is My Fault With This WP_QUERY ? [ Pagination Problem ]
- Custom post type category pages pagination returns 404
- WordPress Custom Post Type Archive, filter by category and get pagination working
- Help with Elementor Pagination CPT archive 404 problem
- PHP variable not regenerating when publishing multiple posts at the same time
- How do I move/order posts with a tag to the end?
- Multiple level category drop-down from the WordPress dashboard
- Cannot add category or custom taxonomy from admin. WordPress site is hosted in Windows 16 server via IIS. No XAMPP or WAMP
- Custom taxonomy rewrite give pagination 404
- Add custom post type settings to wordress default posts
- Next and Previous Posts of Same Parent
- Hide parent categories when clicked, and show it’s childs
- Limit amount of posts made within a custom taxonomy
- Problem with displaying posts in the CPT category
- Filter CPT posts by one or more categories
- Getting categories of posts under a custom taxonomy
- Custom Post Types with a common category for a blog listing
- Add Pagination on Custom Post Type Archive
- Can’t remove front from permalinks for custom taxonomy category page
- How to get categories linked in posts for a specific post type
- Woocommerce search pagination not working
- Custom template Page 2 not working
- Custom post type, organized by categories
- How to display “Category and Post_tag” component in a CPT Gutenberg edit screen?
- How do you paginate a query grouped by month?
- Remove CPT name from permalink but add %category% instead
- How to handle paged param in post and custom-post-type?
- Set a checkmark in a category based on a URL-parameter
- WP Query with categories only shows one post and ignores the category
- Adding custom post type to count in category
- List all posts in a custom post type with pagination (the correct way)
- How to edit this code to get the categories in achieve page?
- Custom Post Type and Category Base Rewrite Issue
- Get the category from custom post type
- Post injections into Site Origins Page builder [closed]
- custom post type pagination error 404
- Custom Post Type + Categories
- How To Show All Custom Post Types In A Category Instead Of Pagination?
- How to create a gallery page with categories?
- Pagination issue on category.php using custom post type query
- Custom Post Slug same as Parents Category Slug
- WordPress posts page for customer filtering and sorting along with category filter
- I am having Trouble to get list of Categories of Custom post Type
- Hierarchy and access control for Custom Post Types (CPT)
- Multiple (two) category postings on the same page.
- Loop filtering Custom Post Types and/or Categories
- Custom Post Type Pagination Paginates Only in URL Structure
- School & class blogs: Categorize with categories or custom posts?
- Custom post type and category link together
- Is it possible to to use custom post type types on a page with the same slug somehow?
- WordPress custom post query with pagination
- Why is my category template ignoring post type?
- Best method to make posts searchable, sortable and filterable – custom field, tag or category?
- How to get custom posts sub category link
- Not sure if I should create multiple custom post type [closed]
- Cross reference custom post types
- Make a custom_post translatable
- Pre-selecting the category for a custom post type
- Next Post links not working in custom post type shortcode
- browse by category and tags?
- Custom Theme With Custom Loops
- Querying Custom Post Type, ordering by Custom Taxonomy Pagination Not Working
- I am trying to hide a custom post type category to logged in users with Pre_Get_Posts
- Custom Post Types strange pagination problem
- Categories filtering in new post
- Conditional statement for if archive page has posts which contain certain taxonomies/categories/tags, show those terms
- Custom post types and category archive
- Pagination with custom query, custom search form, single and pages, ajax and no plugins
- List of Posts and Categories
- How can I show 1 featured post in a styled element, and the next few below differently styled
- can these 3 queries be re-written as 1 query?
- Custom post type pagination – always return first page
- How do you create a custom template to display a category with an image and related posts below?
- How can I list Custom Post Types created with the Types plugin under categories?
- List Taxonomies: Don’t list taxonomy if it has no post – depending on custom post-meta?
- pagination not working for category.php (custom post types in categories)
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- Custom templates for a specific category
- CPT category hierarchy
- Custom post type pagination 404
- Categorise Custom Post Types
- WP the_posts() on single-cars.php get category link
- Category.php template for custom posts
- How to retrieve category of a post in have_post loop?
- Pagination broken by naming conflict between CPT and Page
- Cant get paginations on single.php to work with my custom post types
- Categories and tags for custom post types
- Create new custom post and post category of same name
- Tag page only display 10 posts
- category page for custom post type
- in_category for custom post types
- Number of posts in the archive
- Pagination custom post type not working with rewrite slug
- Pagination Not Working for Custom Taxonomy with Custom Query – 404 Error
- Get parent category id from child category page for custom taxonomy