• Resolved Jellico

    (@catsfoto1se)


    Bug making relevanssi displaying posts from excluded categories?

    Apparently have relevanssi stopped respecting the “Category exclusions” option, because now when I’m testing to search, it will find all posts, even those that are in an excluded category..

    On my site, the news are excluded, but are still found when I’m searching for it (or just pressing the search button without writing anything)

    The page I need help with: [log in to see the link]

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

    (@msaari)

    First of all, if you have content that is not supposed to be searched at all, it’s best to not index it at all. The “Category exclusion” setting has the content in the index, it’s just generally not shown in the search results.

    When you search for nothing, the default WordPress behaviour is to return all posts. So that’s basically what should happen. However, Relevanssi should still use the category exclusion setting – at least that’s what happens on my test site when I run a search without any search term.

    If you install Query Monitor, what does the search query look like when you run an empty search?

    Thread Starter Jellico

    (@catsfoto1se)

    @msaari hi.

    I’ve installed the query l monitor, but there’s so much data, don’t know where to look..

    The exclude has been working before, I tested it for a couple of months ago..

    Could it be some kind of new incompatibility issue with Elementor?

    • This reply was modified 4 years, 4 months ago by Jellico.
    Plugin Author Mikko Saari

    (@msaari)

    Check under Queries > Caller “relevanssi_search()”, there should be a query that begins SELECT DISTINCT(relevanssi.doc). What does that query look like?

    Thread Starter Jellico

    (@catsfoto1se)

    @msaari

    SELECT DISTINCT(relevanssi.doc), relevanssi.*, relevanssi.title * 5 + relevanssi.content * 1 + relevanssi.comment * 0.75 + relevanssi.tag * 1 + relevanssi.link * 0 + relevanssi.author + relevanssi.category * 1 + relevanssi.excerpt + relevanssi.taxonomy + relevanssi.customfield + relevanssi.mysqlcolumn AS tf
    FROM www_relevanssi AS relevanssi
    WHERE relevanssi.term = relevanssi.term
    AND relevanssi.doc NOT IN (
    SELECT DISTINCT(tr.object_id)
    FROM www_term_relationships AS tr
    WHERE tr.term_taxonomy_id IN (5,478))
    ORDER BY tf DESC
    LIMIT 500
    Plugin Author Mikko Saari

    (@msaari)

    There’s a category exclusion there: no posts from the taxonomy terms 5 and 478 should not be included in the results.

    If they still are, then the problem is not in Relevanssi: Relevanssi is excluding them, all right.

    But if you never want to have these posts in the search results, it’s better to do it this way:

    add_filter( 'relevanssi_do_not_index', 'rlv_exclude_cats', 10, 2 );
    function rlv_exclude_cats( $block, $post_id ) {
        if ( has_term( array( 5, 478 ), 'category', $post_id ) ) {
            $block = true;
        }
        return $block;
    }

    Add this to theme functions.php and then rebuild the index. This should make sure those posts are never returned in search results. If it’s not working, check the numbers: usually term taxonomy IDs as reported in the query match exactly to the term IDs this function needs, but not always, so if these do not work, you can replace the numbers with the slugs of the categories, wrapped in apostrophes (like this: array( 'news', 'category_b' ) instead of array( 5, 478 )).

    Thread Starter Jellico

    (@catsfoto1se)

    @msaari hi again!

    The id didn’t work, but the slugs solved the issue thx a lot!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Bug making relevanssi displaying posts from excluded categories’ is closed to new replies.