Widget Logic
Invoke Widget Logic Programatically (6 posts)

  1. stef1979
    Posted 3 years ago #


    Is there any way, I could invoke the configuration of the placement of a widget for a specific posttype programatically?
    I would like to do something like
    createWidgetLogic(WIDGETNAME, WIDGETLOGIC);
    createWidgetLogic("Calendar", "(get_post_type()=='event')");
    so that the Calendar Widget is only displayed with event posts.

    Thank you!


  2. alanft
    Plugin Author

    Posted 3 years ago #

    If get_post_type()=='event' is the logic you need (and it looks good to me), put it in the calendar widget's widget logic text field and see what you get

  3. stef1979
    Posted 3 years ago #

    the logic is ok, I tested it. What I would like to do, is to define that logica from within another plug-in, programatically!

  4. alanft
    Plugin Author

    Posted 3 years ago #

    ah, i get you. ok so the main params for widget logic can be retrieved from the 'widget_logic' option, manipulated and then updated like this…

    …[do stuff to the wl_options hash]…
    update_option('widget_logic', $wl_options);

    The keys of the hash are the widget IDs, the values are the widget logic text. Take care that you control the widget logic text - as it will get EVAL'd.

  5. stef1979
    Posted 3 years ago #

    Thanks for your help. That;s exatcly what I needed.
    I am, however, struggling with the structure of the option value. could you give me a standard example of how you would create a new entry in wl_options?

    Thanks you so much!

  6. stef1979
    Posted 3 years ago #

    I figured it out! Thanks a lot for your support!!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic