• dc23

    (@datenchef)


    Hi! I do have a setup with facet wp and do use relevanssi as search engine. I just want to search in two acf fields “bezeichnung and artikelnummer” and no other field. i do checked the marked in index settings with my cpt products where these fields belong to and set “relevanssi_index_fields_select” to none.

    then i made this code to include the 2 fields

    add_filter( ‘relevanssi_index_custom_fields’, ‘rlv_include_custom_fields’ );

    function rlv_include_custom_fields( $custom_fields ) {
    $included_fields = array( ‘bezeichnung’, ‘artikelnummer’ );
    $custom_fields = array_merge( $custom_fields, $included_fields );
    return $custom_fields;
    }

    and to exclude products content

    add_filter(‘relevanssi_index_custom_fields’, ‘exclude_custom_post_content’);

    function exclude_custom_post_content($custom_fields) {
    if (is_singular(‘products’)) {
    $custom_fields = array_diff($custom_fields, array(‘post_content’));
    }

    return $custom_fields;

    }

    but products content is still searched. i also reindexed after code changes since as a facet user i am used to.

    does anyboy have an idea?

    thanks!

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

    (@msaari)

    You have not excluded post content. Post content is not a custom field, so relevanssi_index_custom_fields doesn’t affect it. Use this instead:

    add_filter( 'relevanssi_index_content', '__return_false' );

    This filter will stop Relevanssi from indexing post content.

    Thread Starter dc23

    (@datenchef)

    Woooh, what a bummer. Thank you for fast reply, really appreciate it. Found the documenation:

    https://www.relevanssi.com/user-manual/filter-hooks/relevanssi_index_content/

    I addeed both

    add_filter( 'relevanssi_index_content', '__return_false' );
    add_filter( 'relevanssi_pre_excerpt_content', '__return_empty_string' );


    reindexed, opened a private fresh window but it still seems that the content of my custom post type products is indexed. tried it a few times but cpt content is still indexed.

    Plugin Author Mikko Saari

    (@msaari)

    If you check the post with the Relevanssi debugger (Settings > Relevanssi > Debugging), is the post content still indexed? Or is the content stored somewhere else in the post?

    Thread Starter dc23

    (@datenchef)

    Thanks, should have find on my own.

    First input Debugging input seems to work fine regarding with the functions.php code ($included_fields = array( ‘bezeichnung’, ‘artikelnummer’ );) or the index plugin options in the admin which i thought they arent working.

    And

    > How does this post look in the database?

    Given any post id of my custom post type products outputs the full content. Where i understand i shouldnt output, right, since we dont index it anymore.

    Plugin Author Mikko Saari

    (@msaari)

    The second one should output the full content, because that’s not what Relevanssi sees, that’s how the post appears in the wp_posts table.

    The first one is the critical: with the post content disabled, the post content field should show up empty there. These are all the words that can be used to find the posts; if the posts are coming up in the results for other words, the search is not Relevanssi.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘how to include only 2 acf fields and no cpt content’ is closed to new replies.