WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I am trying to display pagination from archive.php with my custom post type news but when I click to Next page I am getting 404 page

My Custom Post Type Code:

function codex_custom_init() {
  $labels = array(
    'name'               => 'News',
    'singular_name'      => 'News',
    'add_new'            => 'Add News',
    'add_new_item'       => 'Add New News',
    'edit_item'          => 'Edit News',
    'new_item'           => 'New News',
    'all_items'          => 'All News',
    'view_item'          => 'View News',
    'search_items'       => 'Search News',
    'not_found'          => 'No news found',
    'not_found_in_trash' => 'No news found in Trash',
    'parent_item_colon'  => '',
    'menu_name'          => '1. News'

  $args = array(
    'labels'             => $labels,
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'news' ),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )

  register_post_type( 'news', $args );
add_action( 'init', 'codex_custom_init' );

and My Pagination Code:

    // the query to set the posts per page to 3
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array('posts_per_page' => 2, 'post_type' => 'news' , 'paged' => $paged );
<!-- the loop -->
<?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
    <div class="news-main">
        <div class="news-image"><img src="<?php echo get_field('image'); ?>" /></div>
        <div class="news-container">
            <h1><?php echo the_title(); ?></h1>
            <p><?php echo the_content(); ?></p>
<?php endwhile; ?>
<!-- pagination -->
    <?php next_posts_link(); ?>
    <?php previous_posts_link(); ?>
<?php else : ?>
<!-- No posts found -->
<?php endif; ?>

I am new with WordPress so please some one help me :).

share|improve this question

marked as duplicate by Chip Bennett, tfrommen, s_ha_dum, toscho Oct 4 '13 at 15:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 1 down vote accepted

Your code works fine with me, maybe you need to flush your rewrite rules by just visiting the Settings->Permalinks screen on your dashboard.

Note: Visiting the Permalinks screen triggers a flush of rewrite rules. There is no need to save just to flush the rewrite rules.


share|improve this answer

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