Title: get_query_var returning an array after installing
Last modified: April 24, 2018

---

# get_query_var returning an array after installing

 *  Resolved [Fernando Claussen](https://wordpress.org/support/users/fclaussen/)
 * (@fclaussen)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/get_query_var-returning-an-array-after-installing/)
 * This plugin solved the issue of including meta as part of my search but when 
   I activate it, `get_query_var` starts returning an array instead of a string.
   That is causing the BBPress forum search to break and my search templates to 
   load incorrectly ( in my search.php I check the post type and get a different
   template depending on the result, but since it’s an array, I’m loading the general
   template all the time instead of post_type specific templates ).
 * You can check the BBPress problem here: [https://xtalks.com/discussions/search/billion/](https://xtalks.com/discussions/search/billion/)
 * For my search template logic, I can easily just use $array[0] but it would still
   break bbpress. Any idea on how to fix this?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fget_query_var-returning-an-array-after-installing%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Author [Sumit Singh](https://wordpress.org/support/users/5um17/)
 * (@5um17)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/get_query_var-returning-an-array-after-installing/#post-10238948)
 * Hi,
 * Please check this reply [https://wordpress.org/support/topic/bbpress-and-wp-extended-serach/#post-10238941](https://wordpress.org/support/topic/bbpress-and-wp-extended-serach/#post-10238941)
 * Thanks
 *  Thread Starter [Fernando Claussen](https://wordpress.org/support/users/fclaussen/)
 * (@fclaussen)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/get_query_var-returning-an-array-after-installing/#post-10240147)
 * The zip file you added worked.
    I can search in BBPress.
 * What about my regular search? I am still getting an array from `get_query_var`
   instead of a string.
 *  Plugin Author [Sumit Singh](https://wordpress.org/support/users/5um17/)
 * (@5um17)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/get_query_var-returning-an-array-after-installing/#post-10241554)
 * Thanks for the feedback!
 * About `post_type` query var, `post_type` can be array or string both are valid
   types. Please see the [codex](https://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters)
 * Since this plugin gives you an option to search in selected post types then it
   is obvious you will get an array of post types. If you are writing custom code
   you should handle the array type.
    Also, I am not sure how post type specific
   template can be loaded on search results page because by default WordPress sets
   the `post_type` to `any`. Anyway, an array is the valid type.
 *  Thread Starter [Fernando Claussen](https://wordpress.org/support/users/fclaussen/)
 * (@fclaussen)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/get_query_var-returning-an-array-after-installing/#post-10243382)
 * Hi @5um18
 * I will change my code to work with arrays then.
 * To your question, this is how I do it.
 * I have a general search, that searches the entire site. And I also have `post_type`
   specific search. So in my Webinars post type archive page I have a custom search
   form. That form has a hidden field of `post_type` and value of `webinars`.
 * In my search.php file I have the following:
 *     ```
       get_header(); ?>
   
       	<?php
       		if ( 'webinars' === get_query_var( 'post_type' ) ) {
       			get_template_part( 'template-parts/content', 'search-webinars' );
       		} elseif ('post' === get_query_var( 'post_type' )) {
       			get_template_part( 'template-parts/content', 'search-vitals' );
       		} else {
       			get_template_part( 'template-parts/content', 'search-general' );
       		}
       	?>
       <?php
       get_footer();
       ```
   
 * And that’s how I have separate search result templates.
 *  Plugin Author [Sumit Singh](https://wordpress.org/support/users/5um17/)
 * (@5um17)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/get_query_var-returning-an-array-after-installing/#post-10243845)
 * Hi,
 * Thanks for sharing the code.
 * I would suggest here to use `$_GET['post_type']` instead of `query_var` as you
   are setting post_type in GET request. And WP Extended search respect post_type
   GET request as long as you have selected requested post type in WPES settings.
 * Thanks

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

The topic ‘get_query_var returning an array after installing’ is closed to new replies.

 * ![](https://ps.w.org/wp-extended-search/assets/icon-256x256.png?rev=2436853)
 * [WP Extended Search](https://wordpress.org/plugins/wp-extended-search/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-extended-search/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-extended-search/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-extended-search/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-extended-search/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-extended-search/reviews/)

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)

 * 5 replies
 * 2 participants
 * Last reply from: [Sumit Singh](https://wordpress.org/support/users/5um17/)
 * Last activity: [8 years, 1 month ago](https://wordpress.org/support/topic/get_query_var-returning-an-array-after-installing/#post-10243845)
 * Status: resolved