• Resolved d3d5x1

    (@deraxia)


    I’m using Relevanssi to index my attachments. I only want them to show up in search results for logged in users. Is there any way that can be done?

    I hope you can help, this is a great plugin. Normally, I can set a post status to private to keep logged out users from getting it in search results but not sure what I can do in this case.

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

    (@msaari)

    Unfortunately, you can’t just make an attachment private. That would be a neat solution. However, you can do this:

    add_filter( 'relevanssi_post_ok', function ( $show, $post_id ) {
        if ( ! is_user_logged_in() ) {
            $post = relevanssi_get_post( $post_id );
            if ( 'attachment' === $post->post_type ) {
                $show = false;
            }
        }
        return $show;
    }, 11, 2 );

    This will exclude the attachment posts from the search for non-logged-in users.

    Thread Starter d3d5x1

    (@deraxia)

    That worked, thanks a lot!

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