Support » Plugin: Relevanssi - A Better Search » Private custom fields

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


    It’s possible, but it requires Relevanssi Premium. The free version doesn’t know, which custom field matches the search term, it just knows some custom field did. With the free version, you can make all custom fields private or public, not some of them. With Premium, you can have more fine-tuned control.

    The actual code is fairly simple:

    add_filter('relevanssi_match', 'rlv_private_custom_fields');
    function rlv_private_custom_fields($match) {
    	global $wp_query;
    	$private_custom_fields = array("total_sidebar_layout");
    	if (!$wp_query->is_admin) {
    		$customfield_detail_array = unserialize($match->customfield_detail);
    		if (is_array($customfield_detail_array)) {
    			foreach (array_keys($customfield_detail_array) as $field) {
    				if (in_array($field, $private_custom_fields)) {
    					$match->weight = 0;
    	return $match;

    Just list the names of the private custom fields in the array, and if the search is a frontend search and the custom field matches one of those, the post weight is set to zero.

    Perfect, thank you for your quick return

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Private custom fields’ is closed to new replies.