0

I'm working on a site that allows users to browse through pending posts/content on the front-end.

However, I can't seem to get pagination working with those posts. I've got a custom query that brings up the first page of pending posts on a category page, archive, etc.

But the Page 2, 3, etc. doesn't work.

Any thoughts?

Thanks!

Here's the example code I'm working with:

$args = array(
    'cat'      => $cat_ID,
    'paged' => get_query_var('paged'),
    'showposts' => 50,
    'posts_per_page' => 50,
    'post_status' => 'pending',

);

query_posts($args);

if( have_posts() ) : while (have_posts()) : the_post();

//Post code inserted here

<?php endwhile; ?>
<?php endif; ?>
6
  • Post the code...? Jun 29, 2012 at 22:30
  • I posted the code. This works fine if the posted is published, but for pending posts, I can't seem to find a way to get it working.
    – dfcode3
    Jun 30, 2012 at 1:11
  • Where is this code? More specifically is there a page that users navigate to to view the pending posts? Jun 30, 2012 at 10:21
  • This actually is a modified category page. It works fine when loading that page, but /category/page/2/ does not load. I get a 404 error page. Basically its not finding the "pending posts" in this case. If I change the posts to "published" everything works fine (that is, the published posts show up on paginated pages. Pending posts still do not show). I think that Wordpress is just setup to only deal with published posts on paginated pages. I'm trying to find a way around that.
    – dfcode3
    Jun 30, 2012 at 16:43
  • Yup, the problem is query_posts - so the user navigates to a particular category term page - which you use to display the pending posts? I ask, because it means I know what query you want to change as it goes through pre_get_posts Jun 30, 2012 at 16:55

1 Answer 1

-1

Check this out: http://css-tricks.com/snippets/wordpress/paginate-custom-post-types/ It is meant for custom post type, but I think it would work for you too.


Edit:

The important part about this link is the link was the use of the first lines before the loop:

$temp = $wp_query; 
$wp_query = null; 
$wp_query = new WP_Query(); 
$wp_query->query(here goes the query);

But I think a better solution would be to use pre_get_posts hook, I think it will solve your pagination problem, this is also the best practice.

You can use this code for your pagination:

echo paginate_links( array(
'base' => @add_query_arg('paged','%#%'), 
'format' => '',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'prev_text' => '',
'next_text' => ''
));

If you used the method with the WP_Query you should make sure you have this code at the end of your pagination code:

$wp_query = null; $wp_query = $temp;
3
  • 1
    You're linking to a "normal" paginated template code. Not even a good example of code: wp_query->query('showposts=6&post_type=news'.'&paged='.$paged); . Looks funny...
    – kaiser
    Jun 29, 2012 at 23:48
  • Yea, this solution didn't work. Any other ideas?
    – dfcode3
    Jun 30, 2012 at 18:10
  • Yes, best on your last comment "This actually is a modified category page. It works fine when loading that page, but /category/page/2/ does not load. I get a 404 error page. Basically its not finding the "pending posts" in this case..." You seems to have another problem, I thought you problem was to get the navigation working, not the pagiantion itself
    – ItayXD
    Jun 30, 2012 at 18:43

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.