0

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!

2
  • 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? Commented Nov 3, 2011 at 14:05
  • Permalinks are set to default. Link is generated by next_posts_link(). Thanks :-)
    – Niels
    Commented Nov 3, 2011 at 21:00

1 Answer 1

1

&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

5
  • 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. Commented Nov 3, 2011 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. Commented Nov 3, 2011 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
    Commented Nov 3, 2011 at 20:59
  • Also, the template being called for the initial view is author.php if that helps at all :-/
    – Niels
    Commented Nov 3, 2011 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
    Commented Nov 4, 2011 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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