• I’m using the Widget Logic plugin to “not display” most widgets on posts that are in a specific category (or that category’s archives), so my logic looks like this:
    (!is_category('49') && !in_category('49'))

    It’s been working perfectly… until I added a “Recent Posts” widget into the mix. Once I did that, the widgets below the “Recent Posts” widget stopped displaying at all… but only sometimes. ?? You may know where I’m going with this…

    I eventually figured out that if the last of the five most recent posts (5 being the default setting for the “Recent Posts” widget) was in category 49, the remaining widgets disappeared.

    As best I can figure, that’s because the global $post variable is changed during the “Recent Posts” and my widget logic is checking it and coming back false.

    I’ve solved this for my own purposes by editing the plugin to store the original $post variable in a temporary variable when first loading the page, and then to reassign $post before rendering each widget. There’s probably a much more elegant way to do it, but I thought I would at least tell you about the issue and my solution in case you want to update the plugin.

    https://www.ads-software.com/extend/plugins/widget-logic/

Viewing 1 replies (of 1 total)
  • which recent posts widget is it? the one that comes with WP doesn’t play with $post (that i can see), but does a ‘new WP_Query’.

    either way you should be able to do this without hacking the code but with just widget logic, as the PHP you use in widget logic can be anything.

    in the recent posts widget put in code to preserve $post, then in the next widget you can restore it. this isn’t tested code, but something like:

    recent posts widget
    global $post, $save_my_post; $save_my_post=$post; return (!is_category('49') && !in_category('49'));

    next widget
    global $post, $save_my_post; $post=$save_my_post; return (!is_category('49') && !in_category('49'));

    hope this helps

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Widget Logic] Issues with “Recent Posts” widget’ is closed to new replies.