I have a custom post type named episodes_listing and a custom taxonomy named episodes_category.
My goal was to have pages like domain.com/episodes/season-one. This works great, and if I have a template called taxonomy-episodes_category.php and someone goes to domain.com/episodes/season-one, using the standard WordPress loop it works fine and shows all of the episodes from season one.
However, when I try to add pagination to this, When someone goes to page 2, the url changes to domain.com/episodes/season-one/page/2 and returns 404. I'm not sure how to get pagination to work.
Pagination code after standard loop endwhile:
next_posts_link( 'Older posts' );
previous_posts_link( 'Newer posts' );
My custom post type/taxonomy code is below.
// Register Custom Post Type
function episodes() {
$labels = array(
'name' => _x( 'Episodes', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Episodes', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Episodes', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'all_items' => __( 'All Episodes', 'text_domain' ),
'view_item' => __( 'View Item', 'text_domain' ),
'add_new_item' => __( 'Add New Episode', 'text_domain' ),
'add_new' => __( 'Add New Episode', 'text_domain' ),
'edit_item' => __( 'Edit Item', 'text_domain' ),
'update_item' => __( 'Update Item', 'text_domain' ),
'search_items' => __( 'Search Item', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' )
);
$rewrite = array(
'slug' => 'episodes/%episodes_category%',
'with_front' => false
);
$args = array(
'label' => __( 'episodes', 'text_domain' ),
'description' => __( 'All episodes', 'text_domain' ),
'labels' => $labels,
'supports' => array('title' ),
'taxonomies' => array('episodes_category' , 'post_tag'),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => 'episodes',
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'post',
'query_var' => true,
'menu_icon' => 'dashicons-media-video'
);
register_post_type( 'episodes_listing', $args );
}
function episodes_taxomony() {
$labels = array(
'name' => _x( 'Episodes Categories', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Episodes', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Episode Categories', 'text_domain' ),
'all_items' => __( 'All Items', 'text_domain' ),
'parent_item' => __( 'Parent Item', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'new_item_name' => __( 'New Item Name', 'text_domain' ),
'add_new_item' => __( 'Add new Episode Category', 'text_domain' ),
'edit_item' => __( 'Edit Item', 'text_domain' ),
'update_item' => __( 'Update Item', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
'search_items' => __( 'Search Items', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove items', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used items', 'text_domain' ),
'not_found' => __( 'Not Found', 'text_domain' )
);
$rewrite = array(
'slug' => 'episodes',
'with_front' => false,
'hierarchical' => true
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'query_var' => true,
'rewrite' => $rewrite
);
register_taxonomy( 'episodes_category', array('episodes_listing'), $args );
}