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 am using the WP_Query class to retrieve some posts according to variables set in url.

All working well until we get to paging. The second page (though having posts - tested it by making paged => 2) throws a 404. How can I fix this?

Note: Unusual method of getting author(director) data due to method of adding that content in backend.

<?php /* GET STUFF */

$director_id = get_query_var('author');
$reel = get_query_var('reel');
$info = get_query_var('info');
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;


$director_args = array(
                    'meta_key' => '_metabox_director',
                    'meta_value' => $director_id,
                    'paged' => $page,
                    'types' => $reel,
                    'posts_per_page' => 2, 
                    'post_type' => 'clip',
                    'orderby' => 'menu_order',
                    'order' => 'ASC',
        );  

//query_posts($director_args);
$wp_query = new WP_Query();
$wp_query->query($director_args);

if ($wp_query->have_posts()) : ?>


    <?php next_posts_link('Next' ); ?>
    <?php previous_posts_link('Back' ); ?>

    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

            <!-- Loop the loop -->

    <?php endwhile; ?>




<?php endif; ?>

Url vars on initial view are ?author=2&reel=commercials and on second page ?author=2&reel=commercials?paged=2 but the query won't display the posts.

Thanks!

share|improve this question
    
Got a few questions Niels - Do you have permalinks on? and how is the link being created, by typing it in the address bar or using one of wordpress's functions? –  sanchothefat Nov 3 '11 at 14:05
    
Permalinks are set to default. Link is generated by next_posts_link(). Thanks :-) –  Niels Nov 3 '11 at 21:00
add comment

1 Answer

&reel=commercials?paged=2

That's the problem at the end of that query string. You can't start a query string twice so that ?paged=2 bit is being read as part of the reel parameter's value. The question mark should be another & eg:

?author=2&reel=commercials&paged=2

share|improve this answer
    
Which causes one to ask: how is that query var being appended? WordPress core functions handle this automatically, which has me curious about the implementation. –  Chip Bennett Nov 3 '11 at 13:09
    
True, I assumed @niels-oeltjen was typing it in on the end to test ie. "making paged => 2". It may be that permalinks are currently off hence the query string. –  sanchothefat Nov 3 '11 at 14:03
    
Oops, that's a typo. The correct string is ?author=2&reel=commercials&paged=2. Permalinks are set to default. Link is generated by next_posts_link() –  Niels Nov 3 '11 at 20:59
    
Also, the template being called for the initial view is author.php if that helps at all :-/ –  Niels Nov 3 '11 at 23:22
    
Just to clarify the note in my question regarding retrieving Director content. In the post editor the Director is assigned to the post using a metabox. The user ID of the Director is then retrieved and that is then used to retrieve associated content. –  Niels Nov 4 '11 at 3:17
add comment

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.