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 tried multiple solutions but its not working.

When I go to /page/2, it doesn't work.

I'm executing custom query in index.php of my theme.

if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}

$args = array(
'post_type' => array('post', 'music', 'videos'),
'post_status' => 'publish',
//'meta_key' => 'featured',
//'meta_value' => '1',
'posts_per_page' => 10,
'orderby'=>'date',
'order'=>'DESC',
'paged' => $paged
);

query_posts($args);

Here is the link of my website: http://fattrel.developmentdemo.net/

This page is not working (throwing 404) - http://fattrel.developmentdemo.net/page/2/ (of the format - mywebsite/page/2/)

Just realized this page 2 works - of the format - mywebsite.com/?page=2

share|improve this question

1 Answer 1

This is my working pagination query. I've updated it to use the parameters in your question:

<?php 
if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
    $paged = get_query_var('page');
} else {
    $paged = 1;
}

$args = array(
    'post_type'      => array('post', 'music', 'videos'),
    'post_status'    => 'publish',
    'posts_per_page' => 10,
    'orderby'        => 'date',
    'order'          => 'DESC',
    'paged'          => $paged 
);

// Create new query
$temp = $wp_query; 
$wp_query = null; 
$wp_query = new WP_Query(); 
$wp_query->query( $args );
while ($wp_query->have_posts()) : $wp_query->the_post(); 
?>

<!-- add your content -->

<?php 
    // End the custom loop    
    endwhile; ?>

<?php 
    // This is where I put my pagination, included from another file
    echo get_template_part( 'pagination' ); ?>

<?php
    // Need this to reset the query
    $wp_query = null; 
    $wp_query = $temp;  // Reset
?>

I see you're using numbered pagination, while I am using the default wordpress next and previous pagination. I don't think there will be a problem using this code for either type.

share|improve this answer
    
I added the above code and removed all other code. Still it is giving the 404 error on next page –  dang Dec 9 '12 at 20:32

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.