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

    (@msaari)

    Yes, it’s possible.

    If you want to block certain posts from the search completely, it’s best to remove them from the index in the first place.

    add_filter('relevanssi_do_not_index', 'rlv_block_posts', 10, 2);
    function rlv_block_posts($block, $post_id) {
        $checkbox = get_post_meta($post_id, 'name_of_the_custom_field', true);
        $block = true;
        if (isset($checkbox) && $checkbox == 'on') $block = false;
        return $block;
    }

    This assumes the checkbox custom field gets a value of “on” when it’s checked. Add this code to functions.php, change the name of the custom field and rebuild the index – that should remove all non-checked posts from the index.

    Thread Starter hannakost

    (@hannakost)

    Hi,

    The code didn’t work for me. When I add it to the functions.php there are no results.
    Any idea?

    Thanks!
    Hanna

    Plugin Author Mikko Saari

    (@msaari)

    For some reason the code doesn’t recognise your checkbox custom field. What’s the name of the custom field? Do you have that correct in the code? Does it get value “on” when the checkbox is checked?

    After $block = true;, add this line:

    var_dump($checkbox); exit();

    and go save a post with the checkbox checked – what do you see?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Checkbox custom field’ is closed to new replies.