WordPress.org

Ready to get started?Download WordPress

Forums

Widget Logic
Create a function to use in widget logic using string (5 posts)

  1. Agnes
    Member
    Posted 1 year ago #

    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/

  2. alanft
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  3. Agnes
    Member
    Posted 1 year ago #

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

  4. alanft
    Member
    Plugin Author

    Posted 1 year ago #

    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

  5. Agnes
    Member
    Posted 1 year ago #

    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 :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.