WordPress.org

Ready to get started?Download WordPress

Forums

Problem with Recent Posts widget (2 posts)

  1. lonewolfonline
    Member
    Posted 6 years ago #

    Hi, It appears that my Folding Category Widget (http://wordpress.org/extend/plugins/folding-category-widget/) has found a small problem in the way the Recent Posts widget functions. This may effect other widgets as well.

    Recent Posts widget sets itself a small "loop" to get the latest posts, however it does not reset the current post variable afterwards.

    My plugin (and possibly others) rely upon the $post variable (also get_queried_object_id, get_the_category which also rely on $post) to find out about the current post and its categories. Since the $post variable has been changed by the recent posts widget, the plugin always gets data about the last post on the recent posts widget and therefore does not work.

    This only occurs when the recent post widget appears above (processed before) the folding category widget.

    A small (but messy) fix to the problem is to modify widgets.php in wp-includes:

    Find function wp_widget_recent_entries($args) {
    Add two lines immediately under:

    global $post;
    $oldpost = $post;

    At the very end of the function, before the closing brace add:

    $post = $oldpost;

    Post variable is now correctly retained and folding category widget is happy once again.

    This solution is not ideal however as it involves users modifying their core files, so how can I get the $post variable in my widget after the recent posts widget has been run?

    Obviously I cant use the_ID outside the loop, and $post is invalid. How else can I use get_queried_object_id and `get_the_category' as well as getting access to the current post?

    Thank you for any suggestions.

    Tim

  2. doesnotvalidate
    Member
    Posted 5 years ago #

    I'm having the same issue.

    Basically what this amounts to is that the recent posts widget is unusable and should be either re-written or removed.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic