WordPress.org

Ready to get started?Download WordPress

Forums

Ambrosite Next/Previous Post Link Plus
[resolved] num_results and looping (4 posts)

  1. Justin
    Member
    Posted 1 year ago #

    I'm using num_results to return 2 previous and 2 next links and looping through a custom sort order. This should always return 4 results, but I'm getting 2 instances which don't.

    On my second to last post, the first post is missing. Next should return the last post and the first post.

    On my second post, the last post is missing. Previous should return the first post and the last post.

    My parameters, which are identical for next and previous:

    'order_by' => 'menu_order',
    'order_2nd' => 'post_title',
    'in_same_tax' => 'productline',
    'ex_cats' => $exclude,
    'ex_cats_method' => 'diff',
    'before' => '<span class="nav-next">',
    'after' => '</span>',
    'return' => 'object',
    'loop' => true,
    'num_results' => 2

    Anything I'm doing wrong?

    http://wordpress.org/extend/plugins/ambrosite-nextprevious-post-link-plus/

  2. ambrosite
    Member
    Plugin Author

    Posted 1 year ago #

    Actually it is working the way it is supposed to (or at least, the way it always has). The loop and num_results parameters were never really intended to be used together. It would require a fairly substantial code rewrite to get the result you are looking for.

  3. Justin
    Member
    Posted 1 year ago #

    Thanks for such a quick reply. I can see how it would be a tricky issue to solve, since the problem compounds as the num_results value increases. Since I'm only using 2, I can work around it pretty easily with an extra query on the 2 affected pages. It would be helpful to edit the documentation to note the incompatibility, or at least the known limitations, of using num_results in conjunction with looping.

    If this issue were eliminated the plugin becomes a pretty handy carousel creator, should you decide a substantial rewrite would be super fun to do.

    Thanks again.

  4. ambrosite
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, that's exactly right -- the problem would be a lot easier to solve if I only had to worry about the case where num_results = 2, but in order to make it work for any value, I would probably have to put the query results into an indexed array and do some calculations to determine the position of the current page relative to the last page.

    In any case, I am glad you were able to find a workaround. I am marking this thread as resolved.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.