• Resolved cory

    (@rtkl)


    Hello,

    I am using Relevanssi Premium 1.13.4. I have a problem with a custom search template + custom post type + relevanssi. How can I escape Relevanssi on a custom search template?

    My site has a global search input that uses “search.php” to return many custom post types very well, including authors (users) at /?s=[thesearch] … no problems there.

    I am also using a custom form with inputs that run custom searches for the “current-opening” custom post type (searching jobs on our site):

    page-careers.php contains:

    <input type="text"    name='s' value="" placeholder="" />
    <input type="submit" value="Go" />
    <input type="hidden"  name="post_type"  value="current-opening" />

    /?s=[thesearch]&post_type=current-opening

    Searches through that form go to search.php, but I have a script on search.php that looks for “current-opening” in the URL and does a get_template_part('search', $post_type); to send the search on to a custom template, search-current-opening.php

    search-current-opening.php works fine if Relevanssi is turned *off* — it just returns the “current-opening” post type stuff — the title, some custom fields.

    But, if Relevanssi is turned *on*, it returns the user info instead of current-opening post type info, like “John Doe” instead of the_title(), the permalink and doesn’t return any custom fields … because authors/subscribers don’t share any custom fields with current-openings

    Turn Relevanssi off and everything’s fine.

    Any ideas? I’ve been scouring the Internet trying to figure out how to disable Relevanssi for this particular custom search template, but nothing works. The only thing that works is turning off Relevanssi, but then I can’t use it on my main search

    Thank you,
    CS

    PS: I would show you, if you wanted to see, but I don’t have this on a dev or production site, all local.

    https://wordpress.org/plugins/relevanssi/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter cory

    (@rtkl)

    Well, as usual, I have only myself to blame.

    At some point in my tinkering, I disabled “current-opening” from indexing. So, Relevanssi was just returning anything it could find and ignoring the “post_type” parameter in the URL. “People” happened to be more relevant, I guess.

    All that said, I would like to know how I could escape Relevanssi in the template, if that’s possible.

    Thread Starter cory

    (@rtkl)

    Dang — actually, this is *not resolved.*

    When I turned current-opening back on, I had disabled all the “index user, index author” etc. I turned user indexation and current-opening indexation back on and found I had the same problem I start with.

    So, in my template I am doing a conditional to show nothing if get_post_type() === ‘user’ and that seems to be working… except my count is screwed up.

    Plugin Author Mikko Saari

    (@msaari)

    If you have Premium, then please use the Premium support! That’s what you paid for, and it’ll get you answers usually much faster. I only check this forum once a day, but Premium support gets answered within couple of hours.

    If you have a “post_type” parameter in the search, you shouldn’t be seeing users in the search results in the first place… “post_type” is a bit unreliable, though, and you may want to try “post_types” to see if that works better.

    Anyway, if the count is the only thing that’s wrong, then you can fix the count.

    add_filter('relevanssi_hits_filter', 'rlv_count_posts');
    function rlv_count_posts($hits) {
        global $rlv_count_without_users;
        $rlv_count_without_users = 0;
        foreach ($hits[0] as $hit) {
            if ($hit->post_type != "user") $rlv_count_without_users++;
        }
        return $hits;
    }

    Add that, and now you have the post count without the user profiles in $rlv_count_without_users. If it’s something else you need, just adjust. Does that help?

    Thread Starter cory

    (@rtkl)

    I tried “post_types” instead of “post_type” (no ‘s’) and toggled a lot of Relevanssi controls.

    I believe the ‘s’ did help.

    Thank you!
    Cory

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Disable Relevanssi for Custom Search Template, or fix my misconfig?’ is closed to new replies.