Pagination on custom post types
-
I’m stuck and Ive dig around everywhere for a solution to my problem. Ive got some custom post types and I list them on an archive page with the code below.
I want to add pagination for the custom post type archive pages (I have 4 separate CPT), but when I add the pagination code I get nothing, and when I try adding /2 the the archive page url to see the next 10 results, I get a 404.
Archive page code:
<?php $args = array( 'post_per_page' => '-1', 'post_type' => 'news', 'events', ); $dcpNews = new WP_Query($args); //loop while ($dcpNews->have_posts() ) : $dcpNews->the_post(); ?> <div class="list-container"> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><span class="post-category"> : <?php echo get_the_category_list(', '); ?></span></h3> <span><i><?php the_date()?> </i></span> <span><?php the_excerpt();?></span> </div> <?php endwhile; wp_reset_postdata(); ?>
Here’s the code for the custom post types:
$labels = array( 'name' => 'DCP News', 'singular_name' => 'DCP News', 'add_new' => 'Add New News', 'add_new_item' => 'Add New News', 'edit_item' => 'Edit News', 'new_item' => 'New News', 'all_items' => 'All News', 'view_item' => 'View News', 'searh_items' => 'Search News', 'not_found' => 'No News Found', 'not_found_in_trash' => 'No News Found in Trash', 'menu_name' => 'DCP News' ); $args = array( 'labels' => $labels, 'public' => true, 'supports' => array ('title', 'editor', 'thumbnail', 'excerpt', 'revisions', 'tags'), 'archive' => true, 'menu_icon' => 'dashicons-megaphone', 'rewrite' => array( 'slug' => 'news'), 'taxonomies' => array('', 'post_tag') ); register_post_type('news', $args);
And the code for the custom taxonomy I use to tag them:
register_taxonomy( 'news-category', 'news', array( 'hierarchical' => true, 'label' => 'News Categories', 'query_var' => true, 'rewrite' => array( 'slug' => 'news' ), ) );
Ive been banging my head for hours on this one… and nothing.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Pagination on custom post types’ is closed to new replies.