I have created custom post type for videos. Here is my code.
function video_register() {
$labels = array(
'name' => _x('Video', 'post type general name'),
'singular_name' => _x('Video', 'post type singular name'),
'add_new' => _x('Add New', 'video'),
'add_new_item' => __('Add New Video'),
'edit_item' => __('Edit Video'),
'new_item' => __('New Video'),
'view_item' => __('View Video'),
'search_items' => __('Search Videos'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => null,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title', 'editor', 'thumbnail', 'comments', 'custom-fields')
);
register_post_type('video', $args);
}
and I have displayed this video post at home page using this code.
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$temp = $wp_query;
$wp_query= null;
$vcount = 20;
$wp_query = new WP_Query();
$wp_query->query('posts_per_page='.$vcount.'&post_type=video&paged='.$paged);
It all working fine. But its pagination is giving me 404 error when I hit to /page/2.
This pagination is showing me at homepage only. On category pages it is working fine. I did not understand what I have mistaken. I searched every where on internet but could not found any solution. Please suggest me what is wrong with my code.
pre_get_posts
. You should never change the main query for a custom query on the homepage and any ype of arhive page