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 have a blog Post home page with the following code in home.php:

<div id="primary">
<div id="content" role="main">
<h2 class="page-title">Featured Products</h2>
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
mp_display_products('&post_type=product&paged=' . $paged, $display) ; ?>

<div class="clear index-space"></div>
 </div><!-- #content -->
</div><!-- #primary -->

Now the homepage works just fine, but the ?paged=2 throws an error 404. Don't know why. In products categories the pagination works fine too.

Any help would be appreciated.


Here is a paste of the function mp_display_products()


share|improve this question
is this a secondary query, or are you showing only the product post type on your home page? –  Milo Mar 5 '13 at 3:18
I've added a paste of the called function. Hope this helps. –  Got The Fever Media Mar 6 '13 at 2:42
add comment

2 Answers

Change the line in which you set the variable $paged as follows:

$paged = (get_query_var('page')) ? get_query_var('page') : 1;

And maybe do a wp_reset_query(); before the mentioned line as well (depending on what else is going on in your theme).

// Edit

Here's what I did (and what worked):

$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array (
    'category_name' =>'news',
    'posts_per_page' => 5,
while (have_posts()) : the_post();
    the_title(); echo ' &mdash; '; the_content();

Both ?page=2 and /2 appended onto the URL led to the second page. Maybe you could give the exact code you are using for testing?

share|improve this answer
thanks for your answer, Ive changed the code and it still gives me a 404 –  Got The Fever Media Mar 5 '13 at 2:41
Hm, it works for me. See updated answer. –  t f Mar 5 '13 at 2:58
add comment

To understand why 404 erros occur with pagination, you have to first understand the process WordPress follows when a page is requested.

The query is parsed and the results are queried from the database before the template is loaded. When you create a new query in the template, these results are unrelated to the original query. Whether or not there are additional pages, and how many pages exists, is based on the original default main query, WordPress has no "awareness" of your new custom query in the template.

So the way to fix this is to modify that original query before it is sent to the database via the pre_get_posts action rather than calling query_posts in the template.

function wpa89392_homepage_products( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'post_type', array( 'product' ) );
add_action( 'pre_get_posts', 'wpa89392_homepage_products' );
share|improve this answer
add comment

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.