WordPress.org

Ready to get started?Download WordPress

Forums

Widget Logic
Invoke Widget Logic Programatically (6 posts)

  1. stef1979
    Member
    Posted 1 year ago #

    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/

  2. alanft
    Member
    Plugin Author

    Posted 1 year 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
    Member
    Posted 1 year 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
    Member
    Plugin Author

    Posted 1 year 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…

    $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.

  5. stef1979
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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