Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

<?php 
    // 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 );
    query_posts($args); 
?>
<!-- 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>
        </div>
    </div>
<?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
add comment

marked as duplicate by Chip Bennett, t f, 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.

1 Answer

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.

http://codex.wordpress.org/Settings_Permalinks_Screen#Customize_Permalink_Structure

share|improve this answer
add comment

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