1

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; ?>
7
  • this is part of a page template? also, the if before the while is not needed and is probably messing up your iteration cycle
    – Toote
    Commented Jun 29, 2012 at 23:30
  • According to scribu.net/wordpress/wp-pagenavi/… you should try with "page" variable. it would also be great if you clarified what "doesn't work" means.
    – Toote
    Commented Jun 29, 2012 at 23:32
  • Hi, 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. "page" vs. "paged" didn't change anything for me.
    – dfcode3
    Commented Jun 30, 2012 at 1:09
  • what is your permalink structure and what does the basic page link look like (when you don't specify a page)?
    – Toote
    Commented Jun 30, 2012 at 3:31
  • Sure. The page is example.com/category/category-name. This will show the pending posts with the code above. But that same link with the /page/2/ and up will give a 404 error. I have the permalinks set to /%category%/%postname%/. However, I don't know if that permalinks setting has anything to do with this because "published" posts work fine and will show up with the code above. 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
    Commented Jun 30, 2012 at 16:46

1 Answer 1

0

WordPress pagination will 404 if there are not enough results in the main query to run to that page.

I'm sure there is a better way, but the only way I can think of round it is to use your custom loop in an archive/search page that has more posts than you have drafts.

For example, add your custom loop to the search.php template and reach it by passing a search query that will generate lots of results (e.g. 'a'). Using search.php will include pages, posts and custom post types in the results so will yield more results.

Use paginate_links for the pagination, which will continue to pass the queryvar on each page and after that you should be good.

On a slightly separate note, I would suggest using WP_Query instead of query_posts. See here for why.

1
  • Yea, there really is no answer at this time, other than suggesting the change to the Wordpress dev team. What you say is probably the best alternative I could find. Thanks for your help!
    – dfcode3
    Commented Aug 20, 2012 at 3:13

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.