Last active
August 7, 2025 07:17
-
-
Save webdados/93cf4347cffd5937f8429d8e9af7d9b2 to your computer and use it in GitHub Desktop.
Ignore post_content when searching with Relevanssi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// For all post types | |
add_filter( 'relevanssi_index_content', '__return_false' ); | |
// For some post types | |
add_filter( 'relevanssi_post_content', function( $post_content, $post_object ) { | |
if ( in_array( $post_object->post_type, array( 'post', 'other_cpt' ) ) ) { | |
return ''; | |
} | |
return $post_content; | |
} , 10, 2 ; | |
// OLD VERSION - Remove weight (works, but versions above make more sense) | |
// Relevanssi does not seem to have a way to not index post_content | |
// And even if try you set the weight to zero, the interface will save "1", because of this: | |
// - https://plugins.trac.wordpress.org/browser/relevanssi/tags/4.24.6/lib/options.php#L49 | |
// - https://plugins.trac.wordpress.org/browser/relevanssi/tags/4.24.6/lib/utils.php#L1618 | |
// So, by forcing the option to 0, Relevanssi will effectly NOT use post_content when searching | |
add_action( 'update_option_relevanssi_content_boost', 'my_remove_relevanssi_content_boost', 10, 2 ); | |
function my_remove_relevanssi_content_boost( $old_value, $new_value ) { | |
remove_action( 'update_option_relevanssi_content_boost', 'my_remove_relevanssi_content_boost', 10, 2 ); | |
update_option( 'relevanssi_content_boost', 0 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment