• Resolved HALODIN

    (@halodin)


    Hello,

    The search functionality is causing me a bit of a headache. I’ve blocked most of my site, but the search function is ignoring the status of the page/post and showing an excerpt of blocked content anyway. For instance if I search for information on a restricted page it shows me this:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut lorem sed nisl congue pulvinar. In mattis lacus tortor. Nam augue ipsum, faucibus at pulvinar ac, tempor ac ligula. Duis gravida erat sit amet …… Read More

    If I click on the “Read More” link, the page is blocked which is correct, but it shouldn’t show the public this information.

    Auto Excerpt is not ticked in the wp-settings. If I enable it and set this to a low number, it does limit what the search facility returns, but I want it to return ALL unblocked content and NONE of the blocked content.

    What are my options?

    Thanks,

    Craig.

    https://wordpress.org/plugins/wp-members/

Viewing 15 replies - 1 through 15 (of 24 total)
  • Thread Starter HALODIN

    (@halodin)

    Just to add – This isn’t a theme issue, it happens with “Twenty Ten” version 1.7 as well.

    In my case the information is sensitive information, it isn’t premium content…

    Thanks,

    Craig.

    Thread Starter HALODIN

    (@halodin)

    Anyone there?

    Plugin Author Chad Butler

    (@cbutlerjr)

    If I click on the “Read More” link, the page is blocked which is correct, but it shouldn’t show the public this information.

    You are confusing “it shouldn’t show” with “I’d like it to not show.”

    The plugin is not going to dump content from search results by default. It is intended to use the excerpts as teaser content to drive the user to conversion. That’s what the auto excerpt is for.

    Thread Starter HALODIN

    (@halodin)

    I’m not confusing my words. I’ve created a new test page that’s NEVER been “unblocked” with a single word of “grass” in the page. “Auto Excerpt” is NOT enabled and the word grass now shows up in the search, obviously it shouldn’t.

    Can you offer some advice please?

    Thread Starter HALODIN

    (@halodin)

    “Show excerpts” is also unticked.

    Plugin Author Chad Butler

    (@cbutlerjr)

    If Auto Excerpt is not enabled, you MUST use the ‘more’ tag to create an excerpt.

    Thread Starter HALODIN

    (@halodin)

    That’s the problem I don’t want an excerpt and yet I’ve got one anyway… How do I prevent the search from picking up blocked information?

    Any ideas?

    Thread Starter HALODIN

    (@halodin)

    I still don’t have an answer to my problem, the standard WordPress search is showing blocked content and I can’t see a reason for it.

    Can you offer some advice please?

    Thread Starter HALODIN

    (@halodin)

    Anyone…?

    Thread Starter HALODIN

    (@halodin)

    I posted a request for help 2 weeks ago, can someone offer some advice please?

    Plugin Author Chad Butler

    (@cbutlerjr)

    You could use the pre_get_posts action to add a meta query to only return posts marked as unblocked:

    add_action( 'pre_get_posts', 'custom_posts' );
    function custom_posts( $query ){
    	// if it is a search and the user is not logged in
        if ( is_search() && ! is_user_logged_in() ){
    
    		// if posts/pages are blocked
    		$meta_query = array(
    			array(
    				'key'     => 'unblock',
    				'value'   => 1,
    				'compare' => 'EXISTS',
    			)
    		);
    
            $query->set( 'meta_query', $meta_query );
        }
    }

    This of course assumes that you have set posts to be blocked by default.

    Thread Starter HALODIN

    (@halodin)

    Thanks for the reply. Yes everything is blocked by default. I’ve just added your code to my functions.php and it’s fixed the problem!!!!

    Big Christmas thanks from me!!!

    Cheers,

    Craig.

    Thread Starter HALODIN

    (@halodin)

    Hello,

    I may have been a bit too quick to say this has fixed my problem 100%, it has blocked ALL non-blocked content when not logged in. I have a mixture of blocked and unblocked content. What I’m trying to achieve is this:

    ## WHEN LOGGED IN ##
    1) The search should show both blocked & unblocked content.

    ## WHEN NOT LOGGED IN ##
    1) The search should show unblocked content only.

    Is this something you could help me with please? I have tried to amend your code, but without any luck.

    Regards,

    Craig.

    Thread Starter HALODIN

    (@halodin)

    One point to add, I block posts and pages, so I’m trying to find a solution for both.

    Thanks.

    Thread Starter HALODIN

    (@halodin)

    Posts are ALWAYS blocked, pages are sometimes blocked.

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘WP Search bleeding blocked content’ is closed to new replies.