Quantcast
Channel: User Michael - WordPress Development Stack Exchange
Viewing all articles
Browse latest Browse all 44

Answer by Michael for Pagination in category.php not functioning

$
0
0

if your aim is to restrict the category archive to your post_type 'video' and to 6 posts per page, do not edit category.php, rather use 'pre_get_posts'https://developer.wordpress.org/reference/hooks/pre_get_posts/

example code for your case:

add_action( 'pre_get_posts', 'category_post_type_video_custom' );function category_post_type_video_custom( $query ) {    if ( ! is_admin() && $query->is_main_query() ) {        // Not a query for an admin page.        // It's the main query for a front end page of your site.        if ( is_category() ) {            // It's the main query for a category archive.            // Let's change the query for category archives.            $query->set( 'post_type', array( 'video' ) );            $query->set( 'posts_per_page', 6 );        }    }}

virtually directly taken from https://developer.wordpress.org/reference/hooks/pre_get_posts/#targeting-the-right-query


Viewing all articles
Browse latest Browse all 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>