Title: [Plugin: Widget Logic] Create a function to use in widget logic using string
Last modified: August 20, 2016

---

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

 *  [Agnes](https://wordpress.org/support/users/agneslesagegmailcom/)
 * (@agneslesagegmailcom)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-widget-logic-create-a-function-to-use-in-widget-logic-using-string/)
 * 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/](http://wordpress.org/extend/plugins/widget-logic/)

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

 *  [alanft](https://wordpress.org/support/users/alanft/)
 * (@alanft)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-widget-logic-create-a-function-to-use-in-widget-logic-using-string/#post-2792635)
 * 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/](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.
 *  Thread Starter [Agnes](https://wordpress.org/support/users/agneslesagegmailcom/)
 * (@agneslesagegmailcom)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-widget-logic-create-a-function-to-use-in-widget-logic-using-string/#post-2792639)
 * 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..?
 *  [alanft](https://wordpress.org/support/users/alanft/)
 * (@alanft)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-widget-logic-create-a-function-to-use-in-widget-logic-using-string/#post-2792653)
 * 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
 *  Thread Starter [Agnes](https://wordpress.org/support/users/agneslesagegmailcom/)
 * (@agneslesagegmailcom)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-widget-logic-create-a-function-to-use-in-widget-logic-using-string/#post-2792680)
 * 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.

 * ![](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/)

 * 4 replies
 * 2 participants
 * Last reply from: [Agnes](https://wordpress.org/support/users/agneslesagegmailcom/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-widget-logic-create-a-function-to-use-in-widget-logic-using-string/#post-2792680)
 * Status: not resolved