Title: Invoke Widget Logic Programatically
Last modified: August 21, 2016

---

# Invoke Widget Logic Programatically

 *  [stef1979](https://wordpress.org/support/users/stef1979/)
 * (@stef1979)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/invoke-widget-logic-programatically/)
 * Hi
 * 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); e.g. createWidgetLogic(“Calendar”, “(get_post_type()
   ==’event’)”); so that the Calendar Widget is only displayed with event posts.
 * Thank you!
 * [http://wordpress.org/extend/plugins/widget-logic/](http://wordpress.org/extend/plugins/widget-logic/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [alanft](https://wordpress.org/support/users/alanft/)
 * (@alanft)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/invoke-widget-logic-programatically/#post-3854281)
 * 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
 *  Thread Starter [stef1979](https://wordpress.org/support/users/stef1979/)
 * (@stef1979)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/invoke-widget-logic-programatically/#post-3854282)
 * the logic is ok, I tested it. What I would like to do, is to define that logica
   from within another plug-in, programatically!
 *  [alanft](https://wordpress.org/support/users/alanft/)
 * (@alanft)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/invoke-widget-logic-programatically/#post-3854290)
 * 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…
 *     ```
       $wl_options=get_option('widget_logic');
       …[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.
 *  Thread Starter [stef1979](https://wordpress.org/support/users/stef1979/)
 * (@stef1979)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/invoke-widget-logic-programatically/#post-3854307)
 * 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!
 *  Thread Starter [stef1979](https://wordpress.org/support/users/stef1979/)
 * (@stef1979)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/invoke-widget-logic-programatically/#post-3854319)
 * I figured it out! Thanks a lot for your support!!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Invoke Widget Logic Programatically’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/widget-logic_c8dde5.svg)
 * [Widget Logic](https://wordpress.org/plugins/widget-logic/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/widget-logic/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/widget-logic/)
 * [Active Topics](https://wordpress.org/support/plugin/widget-logic/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/widget-logic/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/widget-logic/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [stef1979](https://wordpress.org/support/users/stef1979/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/invoke-widget-logic-programatically/#post-3854319)
 * Status: not resolved