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();


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.

  • as @Rarst said, you should be using pre_get_posts. You should never change the main query for a custom query on the homepage and any ype of arhive page – Pieter Goosen Jan 14 '15 at 19:04

Pagination cannot be reliably implemented in template. It is resolved during load way before template it ever reached.

Unless you implement it from scratch (complete with rewrite) you need to be using pre_get_posts or other related hook to modify main query. Look around the site, there are plenty answer on topic of here.

  • Sorry, I did not understand your point – johnmicky Jan 14 '15 at 18:19
  • @johnmicky which is why you are up for a lot of research on topic to implement this properly. :) Please search the site for answers on how to use pre_get_posts for starters. – Rarst Jan 14 '15 at 19:00

Since you using this: get_query_var('page') Try this change of 'paged' to 'page' for the variable name.

  • I used this, this is not worked – johnmicky Jan 14 '15 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.