WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Widget Logic] Create a function to use in widget logic using string

[Plugin: Widget Logic] Create a function to use in widget logic using string

  • Agnes

    @agneslesagegmailcom

    I am aiming to check if my search is for a certain custom post type (objects) or not, and dsiplay a different search template – but alss different widgets.
    I check like this for the template:

    <?php
    // Checks on the search string, and then sends to either all or object search
    $is_post_type = $_GET['post_type'];
    	if ('objects' == $is_post_type )
    		include( 'search-objects.php');
    	else
    		include( 'search-all.php');
    ?>

    Now for widget logic to be able to display the right widget, I try create a function in functions.php:

    function is_objects_search()
    {
    $is_objects_search = $_GET['post_type'];
    	if ('objects' == $is_post_type )
    		return true;
    	else
    		return false;
    }

    But when I put is_objects_search() in widget logic, it does not display 🙁

    http://wordpress.org/extend/plugins/widget-logic/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author alanft

    @alanft

    to use functions.php functions you need to be sure to set the “Load logic” setting to at least the “after the theme loads” setting

    See http://wordpress.org/extend/plugins/widget-logic/installation/

    That’s not a guaranteed fix, but without doing that your widget logic might throw errors where you don’t expect it.

    Agnes

    @agneslesagegmailcom

    Hi Alan, thanks for the insight! I updated the plugin to do that… but it does not help unfortunately.
    I guess the problem is rather in the way I edited and call the function..?

    Plugin Author alanft

    @alanft

    yeah, your function does this

    $is_objects_search = $_GET[‘post_type’];

    but then tests this

    if (‘objects’ == $is_post_type )

    and $is_post_type hasn’t been defined in the function

    Agnes

    @agneslesagegmailcom

    Right, but in fact this is because I copied the function wrong after I tried several thgings.

    The function was (and that still does not work):

    function is_objects_search()
    {
    $is_objects_search = $_GET['post_type'];
    	if ('objects' == $is_object_search )
    		return true;
    	else
    		return false;
    }

    Thanks for trying to help, I appreciate 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Widget Logic] Create a function to use in widget logic using string’ is closed to new replies.