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

I've read many posts about the same problem but none seems to work for me.

I have a query for a custom post into the index.php. When I go to page 2 I get a 404 error. The same code works like a charm in any static page.

<?php get_header(); ?>
            <div id="content">
                <div id="inner-content" class="wrap clearfix">
                    <div id="main" class="clearfix main-index" role="main">
                        <h5 class="mini-title">Latest Works Added</h5>
                        <?php wp_reset_query();?> 
                        // the query
                        $args = array('post_type' => 'work', 'posts_per_page' => 2, 'paged' => $paged);
                        $the_query = new WP_Query( $args ); 

                        <?php if ( $the_query->have_posts() ) : ?>

                        <!-- pagination here -->

                        <!-- the loop -->
                        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
                            <article id="post-<?php the_ID(); ?>" class="fourcol home-article" role="article">
                                <a href="<?php echo the_permalink();?>">
                                    <table class="table">
                                                <td><h3><?php the_title(); ?></h3></td>

                                                // All Artists                      
                                                $query = '
                                                    PREFIX dcterms: <http://purl.org/dc/terms/> 
                                                    PREFIX foaf: <http://xmlns.com/foaf/0.1/>
                                                    SELECT distinct ?url ?name 
                                                    WHERE   {
                                                        <'.get_permalink().'> dcterms:creator ?url .
                                                        ?url foaf:name ?name
                                                $result = $store->query($query, 'rows');
                                                if (!empty($result)) {
                                                    echo '<td><h3>';
                                                    $names = array();
                                                    foreach ($result as $row) {
                                                        array_push($names, $row['name']);
                                                    echo implode(', ', $names);
                                                echo '</h3></td>';
                                            $first_image = catch_that_image();
                                            if ($first_image != '') { ?>
                                                <td colspan="2" class="img">
                                                    <img src="<?php echo $first_image;?>" alt="<?php the_title(); ?>" />
                                            <?php } ?>
                        <?php endwhile; ?>                      
                        <?php else:  ?>
                          <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
                        <?php endif; ?>
                    <nav class="page-navigation">
                    $big = 999999999; // need an unlikely integer
                     echo paginate_links( array(
                        'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
                        'current' => max( 1, get_query_var('paged') ),
                        'prev_text'    => __('« Previous'),
                        'next_text'    => __('Next »'),
                        'total' => $the_query->max_num_pages
                    ) );
<?php get_footer(); ?> 
share|improve this question

Ok, I found a solution that I can't explain: I had to change Settings > Reading > Blog pages show at most = 1

share|improve this answer
this is really just masking the problem, not solving it. for an explanation of what's happening, see this answer. – Milo Dec 22 '13 at 23:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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