• Resolved elrafo

    (@elrafo)


    Hi there, I have a small problem with the posts order.
    I want to publish the last three published posts but in reverse order. If I change the order from ascent to descent, the plugin indeed publishes the right posts but I want to change the order…
    For instance, the plugin outputs

    post 18
    post 17
    post 16

    and I would like to output

    post 16
    post 17
    post 18

    If I change the order from descent to ascent, the plugins outputs

    post 1
    post 2
    post 3

    So I think I have to modify the code in the view, but I am not sure how to do this.
    Can you help?

    thanks

    raf

    https://wordpress.org/plugins/flexible-posts-widget/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter elrafo

    (@elrafo)

    OK I think this is the line that fetches the posts…is there a way to add something to display them in a reverse order?

    while( $flexible_posts->have_posts() ) : $flexible_posts->the_post(); global $post; ?>

    thanks

    Plugin Author DaveE

    (@dpe415)

    Hi elrafo,

    I haven’t been ignoring your thread. In fact, I’ve thought a lot about how this might be possible. As it stands, I’m pretty confident that you’d need to reverse sort the array of results manually with PHP. I can’t think of a way that WordPress would allow you to reverse the order of the results after it has been queried. Essentially you’re querying for 3 posts ordered by newest and then you want to reorder your results from oldest to newest.

    This wouldn’t be a FPW as much as an issue with how WordPress generates it’s own queries. Since this is beyond the scope of FPW, I can’t really provide you with an easy solution here.

    I’m sorry I’m not more help on this one.

    Thread Starter elrafo

    (@elrafo)

    OK thanks anyway.
    Just one thing, in the code above, $flexible_posts is an array that contains the posts I need (with the settings I specified in the widget)? Is it enough just to re-order this array before the while function?

    thanks again.

    elrafo

    Plugin Author DaveE

    (@dpe415)

    The reference to $flexible_posts there is a PHP object containing the WordPress query details as well as the results. There is one property in the object called posts which contains the complete set of posts returned by the query. I’d suggest reading over the WP_Query documentation as that is how all result sets are generated in WordPress, including the ones used by FPW.

    Thread Starter elrafo

    (@elrafo)

    Ok, I found a solution and wanted to post it, maybe someone will need it one day.
    So I just added the line:

    $flexible_posts->posts = array_reverse($flexible_posts->posts);

    that line reverts the order of all the posts.

    I just add it in a custom view under this condition if( $flexible_posts->have_posts() ):

    Anyway, thanks a lot DaveE for your support, and merry xmas and happy holidays…

    ps: Oh, nearly forgot, I found the solution on this post: http://css-tricks.com/forums/topic/how-to-display-wordpress-loop-pages-in-reverse-order-not-with-orderasc/

    Plugin Author DaveE

    (@dpe415)

    Thanks for posting this!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘post order’ is closed to new replies.