Hi,
I’ve asked a similar question before but I went off on a bit of a tangent!
I’m wondering how to alter the fields shown in a widget based on the context of the post being edited. Using GET[‘post’] doesn’t work, I think due to the use of caching and/or ajax. I’ve tried that both in get_widget_form and using the ‘siteorigin_widgets_form_options_…’ filter.
Is there a best practice approach to achieve this or is it generally recommended not to modify widgets on the fly in this way?
Any other ideas to achieve what I’m after would be appreciated.
Thanks
Hi C,
Thanks for getting in touch. This is possible using the `siteorigin_widgets_form_options_WIDGETBASEID` filter. This filter is applied after caching, so you don’t need to worry about the wrong fields being cached.
As an example of how to use this filter, here’s adding a Color field to the SiteOrigin Editor widget if the current post type is page.
Kind regards,
Alex
Hi Alex,
Well that’s annoying, I could have sworn I’d tried this! I guess I wasn’t using $_POST[‘postId’].
Anyway, thanks very much, I’ll keep that in mind for the future.