WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] What Conditional Tag can I use to identify the WP Custom Fields Search results? (7 posts)

  1. Eric Rasch
    Member
    Posted 4 years ago #

    I am trying to use a certain template when displaying results from a search performed with the WP Custom Fields Search plugin.

    To do so, I am using these Conditional Tags: <?php if ( is_home() || is_front_page() && !(is_search()) ) { ?> HTML CODE <?php } else { ?> HTML CODE <?php } ?>

    The problem I'm running into is the search results page is falling into the "is_home" & "is_frontpage" condition. It doesn't seem to be obeying the "is_search" at all.

    Here's what a search results URL looks like
    //mywordpresswebsite/?search-class=DB_CustomSearch_Widget-db_customsearch_widget&widget_number=preset-1&cs-post_title-0=[SEARCHTERM]&search=Search

    It appears the WP Custom Fields Search plugin does not consider itself a search page. Is there a way I can force it to exist as a search page and fall within the "is_search" condition?

    http://wordpress.org/extend/plugins/wp-custom-fields-search/

  2. Eric Rasch
    Member
    Posted 4 years ago #

    I think I made this more complicated for myself than it had to be. have a lot of template files in my theme directory, but I don't have a home.php. I'm going to make my homepage follow the home.php template and see if that clears up my search/subpage template problem.

  3. Eric Rasch
    Member
    Posted 4 years ago #

    So that didn't work. I moved my index.php to home.php and the WP Custom Fields Search results still show up as though it thinks it is the homepage.

    Any thoughts on code I can add to this plugin to make it not use the homepage template? Any of this make sense?

  4. seborgarsen
    Member
    Posted 4 years ago #

    Any luck?

  5. Eric Rasch
    Member
    Posted 4 years ago #

    Short answer: yes!

    Nothing worked the way I was trying to code, so I had to go around the issue. Basically what I did was to code my search.php to point to another search template if the search came in from the website's main search, otherwise use the custom search template for everything else.

    Here's how to do this...

    Modify your search.php file in your theme:

    <?php
    	/* Template Name: Search Results */
    	$search_refer = $_GET["site_section"];
    	if ($search_refer == 'blog') { load_template(TEMPLATEPATH . '/search-sitesearch.php'); }
    	else { load_template(TEMPLATEPATH . '/search-customfieldsearch.php'); };
    ?>

    Then modify your main website search to include the search_refer parameter from the above code. Here's my site search form code:

    <form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
    	<input type="text" name="s" id="s" value="Search everything..." onblur="if(this.value=='') this.value='Search';" onfocus="if(this.value=='Search everything...') this.value='';" />
    	<input type="hidden" name="site_section" value="blog" class="hidden" />
    	<button type="submit" id="searchsubmit" value="Search" class="submit">Submit</button>
    </form>

    In the hidden input class above we are telling any searches coming from this form need to have the value of 'blog' along with it. In the first piece of code above we tell WP which template to use if the search_refer equals 'blog'.

    Let me know if I need to explain this more. The Custom Field Search is awesome, but it's quirky and doesn't seem to be too flexible or supported.

  6. Eric Rasch
    Member
    Posted 4 years ago #

    Of course, there's always this: How to Customize Multiple Search Result Pages in WordPress: http://tinyurl.com/l5m3ln

  7. seborgarsen
    Member
    Posted 4 years ago #

    Really interesting, thanks alot!!!

Topic Closed

This topic has been closed to new replies.

About this Topic