Support » Plugins » What Conditional Tag can I use to identify the WP Custom Fields Search results?

  • Resolved Eric Rasch


    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

    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?

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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.

    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?

    Any luck?

    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:

    	/* 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>

    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.

    Of course, there’s always this: How to Customize Multiple Search Result Pages in WordPress:

    Really interesting, thanks alot!!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘What Conditional Tag can I use to identify the WP Custom Fields Search results?’ is closed to new replies.