• Resolved Fernando Claussen

    (@fclaussen)


    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/

    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 to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Sumit Singh

    (@5um17)

    Thread Starter Fernando Claussen

    (@fclaussen)

    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

    (@5um17)

    Thanks for the feedback!

    About post_type query var, post_type can be array or string both are valid types. Please see the codex

    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

    (@fclaussen)

    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

    (@5um17)

    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.