Forum Replies Created

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

    (@halodin)

    Excellent news, thanks for the update!

    Whilst I have your ear you could really do with a link back to the auction main page from within each listing. It would make it easier to navigate without using the back-button. It isn’t intuitive for the old guys who use my site 🙂

    Thanks,

    Craig.

    Thread Starter HALODIN

    (@halodin)

    It’s OK I’ve sorted it. Adding “$query->is_main_query()” as a condition to the if statement seems to have fixed it.

    // PREVENT SEARCH SHOWING BLOCKED PAGE & POST CONTENT
    
    add_action( 'pre_get_posts', 'custom_posts' );
    
    function custom_posts( $query ){
        if ( $query->is_main_query() && is_search() && ! is_user_logged_in() ){
    		$meta_query = array(
    			array(
    				'key'     => '_wpmem_block',
    				'value'   => '0',
    				'compare' => '=',
    			)
    		);
            $query->set( 'meta_query', $meta_query );
        }
    }
    Thread Starter HALODIN

    (@halodin)

    Thank you, now I’ve blocked and then unblocked my pages which updates the new meta column and then updated the meta query, all of my non-blocked posts/pages are showing in the search for non-logged in users… Fantastic thank you!

    I fully understand your point of view with giving priority to paying customers, but it wasn’t clear if I’d paid for support I’d receive a faster answer on this issue, it might be in your interest to flag this. If I have any urgent future questions, I’ll make sure I go through this channel.

    Thanks again!

    Craig.

    Thread Starter HALODIN

    (@halodin)

    I don’t understand, why does it take so long to get help here? I posted my first of the second series of replies around the beginning of January, it’s now 3 weeks on and I still haven’t received a reply…

    Please can I have some help????

    Thread Starter HALODIN

    (@halodin)

    Forgot my backticks!

    I’ve tried this as well and it doesn’t work either…

    // PREVENT SEARCH SHOWING BLOCKED PAGE & POST CONTENT
    if ( is_search() ){
        if ( ! is_user_logged_in() ){
            // your not logged in code
    	$meta_query = array(
                                array(
                                      'key'     => 'unblock',
                                      'value'   => 1,
                                      'compare' => 'EXISTS',
                                     )
                               );
        } else {
            // your logged in search code
    	$meta_query = array(
                                array(
                                      'key'     => 'block',
                                      'value'   => 1,
                                      'compare' => 'EXISTS',
                                     )
                               );
        }
    }

    Could I have some more help please?

    Thanks,

    Craig.

    Thread Starter HALODIN

    (@halodin)

    I’ve tried this as well and it doesn’t work either…

    // PREVENT SEARCH SHOWING BLOCKED PAGE & POST CONTENT
    if ( is_search() ){
    if ( ! is_user_logged_in() ){
    // your not logged in code
    $meta_query = array(
    array(
    ‘key’ => ‘unblock’,
    ‘value’ => 1,
    ‘compare’ => ‘EXISTS’,
    )
    );
    } else {
    // your logged in search code
    $meta_query = array(
    array(
    ‘key’ => ‘block’,
    ‘value’ => 1,
    ‘compare’ => ‘EXISTS’,
    )
    );
    }
    }

    Could I have some more help please?

    Thanks,

    Craig.

    Thread Starter HALODIN

    (@halodin)

    So just to reiterate, all 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.

    Thanks,

    Craig.

    Thread Starter HALODIN

    (@halodin)

    It’s probably easier to read like this:

    // PREVENT SEARCH SHOWING BLOCKED PAGE & POST CONTENT
    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',
    			)
    		);}
    
         elseif ( is_search() && is_user_logged_in() ){
    
                    // if posts/pages are unblocked
    		$meta_query = array(
    			array(
    				'key'     => 'block',
    				'value'   => 1,
    				'compare' => 'EXISTS',
    			)
    		);}
    
            $query->set( 'meta_query', $meta_query );
    }

    Either way it doesn’t work. I had a look in MySQL to see if I could work out which columns/values relate to “key”, “value” and “compare”, but I couldn’t relate this meta query to the data. I’m a bit stuck now.

    Cheers,

    Craig.

    Thread Starter HALODIN

    (@halodin)

    and every other variation on the elseif statement:

    {$meta_query = array(array(‘key’ => ‘unblock’, ‘value’ => 0, ‘compare’ => ‘EXISTS’,));}

    etc…

    Thread Starter HALODIN

    (@halodin)

    I tried this (I’m not a developer!) but it didn’t change the behavior of the search. Unblocked pages are still blocked by the search when not logged in.

    // PREVENT SEARCH SHOWING BLOCKED PAGE & POST CONTENT
    add_action( ‘pre_get_posts’, ‘custom_posts’ );
    function custom_posts( $query ){
    if ( is_search() && ! is_user_logged_in() )
    // if posts/pages are blocked
    {$meta_query = array(array(‘key’ => ‘unblock’, ‘value’ => 1, ‘compare’ => ‘EXISTS’,));}

    elseif ( is_search() && is_user_logged_in() )
    // if posts/pages are unblocked
    {$meta_query = array(array(‘key’ => ‘block’, ‘value’ => 0, ‘compare’ => ‘NOT EXISTS’,));}

    $query->set( ‘meta_query’, $meta_query );
    }

    Thread Starter HALODIN

    (@halodin)

    Posts are ALWAYS blocked, pages are sometimes blocked.

    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)

    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)

    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)

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

Viewing 15 replies - 1 through 15 (of 37 total)