• Hi,

    Exclude these posts/pages from search:
    Enter a comma-separated list of post/page IDs that are excluded from search results. This only works here, you can’t use the input field option (WordPress doesn’t pass custom parameters there).

    I wonder if there is a workaround to get this beautiful plugin to work with a custom searchform.

    I have split my website to two versions/categories: Benelux and International

    A person that selects “Benelux” on the startpage will be redirected to http://www.example.com/benelux or if he/she selects international http://www.example.com/international

    Because its still the same website and not a multi-site the search result will still pull information from pages linked to benelux and vice versa.

    I think the workaround is possible to make a benelux-search.php and international-search.php. But as stated above in the quote its not possible to use the input field option.

    So i hope some one has an idea on how to get this resolved?

    One idee would be to duplicate the relevanssi plugin and somehow define one plugin for benelux and one for international…

    One other idee is to give all posts and pages a tag “benelux or international” (and use plugin Tag Pages) and let relevanssi only search on tags. Im not sure if this is possible with the current install.

    Im using Sparkling theme from colorlib:

    search.php(pagebin)
    searchform.php(pagebin)
    content.php(pagebin)

    https://ww.wp.xz.cn/plugins/relevanssi/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Sure, there are many ways to deal with this in Relevanssi. Easiest would be to tag the content (if you use tags for something else as well, better make it a custom taxonomy that exists just for this one thing, it’s much cleaner that way) and then have the search forms restrict the searches to the correct taxonomy term. That’s quite easy.

    As long as you have some way of identifying which posts are Benelux and which are International, this is not a difficult thing to do, and certainly doesn’t require complicated things like duplicated plugins or separate search templates.

    Thread Starter Taro

    (@sicktb)

    Thanks for your answer, this is really good news!

    Made the custom taxonomy for post and pages.
    see the function code here

    I tried the option with separate search templates because i need a different search output for an specific post or page. But the code that i use makes the search option very slow…

    <?php
    				  $post = $wp_query->post;
    				  if (in_category('benelux')) {
    					  include(STYLESHEETPATH.'/benelux-search.php');
    				  } elseif (in_category('international')) {
    					  include(STYLESHEETPATH.'/international-search.php');
    				  }
    				  else{
    					  include(STYLESHEETPATH.'/default-search.php');
    				  }
    				?>
    Thread Starter Taro

    (@sicktb)

    <form role="search" method="get" class="form-search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
      <div class="input-group">
      	<label class="screen-reader-text" for="s"><?php _e( 'Search for:', 'sparkling' ); ?></label>
        <input type="text" class="form-control search-query" placeholder="<?php echo esc_attr_x( 'Search&hellip;', 'placeholder', 'sparkling' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label', 'sparkling' ); ?>" />
        <span class="input-group-btn">
          <button type="submit" class="btn btn-default" name="submit" id="searchsubmit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'sparkling' ); ?>"><span class="glyphicon glyphicon-search"></span></button>
        </span>
      </div>
    </form>

    Maybe it’s easier to do something like this with the above code

    if post or page contains taxonomy benelux only show results with taxonomy benelux

    if post or page contains taxonomy international only show results with taxonomy international

    else

    show all results

    Thread Starter Taro

    (@sicktb)

    the custom taxonomy is not giving a output. 🙁

    I found the plugin Add Categories to Pages, this plugin uses the basic post Categories. If i put the same category to a single post and page i get a correct result.

    Plugin Author Mikko Saari

    (@msaari)

    Separate templates are difficult to set up and may not work all that well with Relevanssi. It’s probably better to just use the one search template and style it differently depending on the target.

    Adding

    <input type="hidden" name="location" value="benelux" />

    to the search form should restrict the search to Benelux results.

    Thread Starter Taro

    (@sicktb)

    Hi Mikko thank for the help. Seems that the function that i made works with this input type(better than the category).

    Getting close to the final result!

    It’s probably better to just use the one search template and style it differently depending on the target.

    Just like i mentioned above?

    if post or page contains taxonomy benelux only show results with taxonomy benelux
    
    if post or page contains taxonomy international only show results with taxonomy international
    
    else
    
    show all results

    Plugin Author Mikko Saari

    (@msaari)

    Yes, I suppose so.

    Thread Starter Taro

    (@sicktb)

    Ok, now just have to wait till a programmer can help me 🙂

    I’m not a great php programmer all i know is that i can use the wp_get_post_terms() to get what i need.

    Thanks for your help!

    ps: i’ll post the solution when i got it. So others can use this together with Relevanssi.

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

The topic ‘custom searchform template’ is closed to new replies.