WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The site I'm working on is a talent website that has actors names, headshots, and resume all created with post_title, featured images, and custom fields.

I am using Relavanssi to make my search results work a little better. However, I am running into a problem where if the user search for "John" it works well with all the actors with "John" in their name come first and then anyone with "John" in their resume (custom fields) come after.

But if the user search for, say, "Spanish" (meaning they are looking for an actor that speaks Spanish) the results come up randomly and not in any order. I want them to be ordered by the title of the post (which is also the name of the actor).

So, short version: If a user searches for a name, it should come up with those names first. If a user searches for a field it should come up as alphabetical.

I realize that I probably need two different search forms for this or at least two different fields, and I know how to create multiple forms with hidden fields to differentiate (which is fine), but I don't know how to make that work and still use Relavanssi or a similar plugin to run both searches for me.

share|improve this question
The whole point of Relavanssi, as I understand it, is to order posts by relevance. I doubt that you get results "randomly and not in any order". You get results in the order that Relavansii's algorithm thinks is the correct order by relevance. It just may not be obvious to you. So, if you are going to interrupt this, what criteria would you use to decide when and when not to order by relevance? – s_ha_dum Mar 24 '13 at 18:29
Yeah, that's my conundrum. I think I would have to fork the plugin pretty badly to make it work now that I'm looking at it. It might be easier for me to just build my own solution using custom queries. I was hoping to avoid that, but you're right that I don't really know what the criteria would be to separate the two different search options using the plugin... Thanks for pushing me in that direction, I guess I was probably just looking for validation that I was going to have to make my own solution! – Eckstein Mar 24 '13 at 18:59
There are a lot of hooks in Relevansii. If you knew what you wanted to try to do, it may be possible. Even if you make your own solution you have to answer that question :) – s_ha_dum Mar 24 '13 at 19:02
Well, what I think the best solution would be is to have 1 search field with a checkbox option below it labeled "search resumes only". If the form is submitted with an empty checkbox, it would sort the results by relevance, if it was submitted with the checkbox checked, it would sort the results by post title. – Eckstein Mar 24 '13 at 19:06
I'm going to go research the Relavansii hooks now and see if I can figure it out. – Eckstein Mar 24 '13 at 19:16

I don't have Relevansii installed but it looks like you can hook to relevanssi_search_ok and return false, and Relevansii will pass back the unmodified search.

add_filter('relevanssi_search_ok', '__return_false');

I am going to assume that Relevansii is using the ordinary search form provided by the theme, meaning that you could modify, or create, searchform.php to include the checkbox mentioned in a comment to question:

what I think the best solution would be is to have 1 search field with a checkbox option below it labeled "search resumes only"

Something like (Twenty Eleven's form in the example):

<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    <label for="s" class="assistive-text"><?php _e( 'Search', 'twentyeleven' ); ?></label>
    <input type="text" class="field" name="s" id="s" placeholder="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
    <input type="checkbox" name="torelornottorel" />
    <input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />


function relavansii_toggle() {
  if (is_search() && isset($_GET['torelornottorel'])) {
    return false;
add_filter('relevanssi_search_ok', 'relavansii_toggle');

This software comes with no promise of fitness for any purpose including fitness for the purpose for which it was intended.

Maybe it will get you started though.

share|improve this answer
Thank you, this is a great start! I will update with final solution once I get it implemented. – Eckstein Mar 24 '13 at 19:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.