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.

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();?> 
                        <?php 
                        // 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">
                                        <tbody>
                                            <tr>
                                                <td><h3>Title</h3></td>
                                                <td><h3><?php the_title(); ?></h3></td>
                                            </tr>
                                            <tr>
                                                <td><h3>Author</h3></td>
                                                <?php
                                                require_once'wp-content/themes/p-dpa/rdfa/lib/arc2/ARC2.php';
                                                include_once('wp-content/themes/p-dpa/rdfa/connect_to_store.php');

                                                // 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>';
                                                ?>
                                            </tr>
                                            <?php
                                            $first_image = catch_that_image();
                                            if ($first_image != '') { ?>
                                            <tr>
                                                <td colspan="2" class="img">
                                                    <img src="<?php echo $first_image;?>" alt="<?php the_title(); ?>" />
                                                </td>
                                            </tr>
                                            <?php } ?>
                                        </tbody>
                                    </table>
                                </a>
                            </article>
                        <?php endwhile; ?>                      
                        <?php else:  ?>
                          <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
                        <?php endif; ?>
                    </div>
                    <nav class="page-navigation">
                    <?php
                    $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
                    ) );
                    ?>
                    </nav>
                </div>
            </div>
<?php get_footer(); ?> 
share|improve this question

1 Answer 1

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
1  
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

 
discard

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.