This topic has 17 replies, 3 voices, and was last updated 8 years by Andrei.

  • Author
  • #99918
     dsniche
    Participant

    If I place the search box in the homepage and I try to do a search as an unregistered new user, the site shows me the search results. Is there a way to hide the search results until after the new user has finished the registration process?

    #100010
     Radu
    Moderator

    Hi,

    Here is a code that allows only logged in users to search.

    COPY CODE
    
    function SearchOnlyForLoggedInUsers( $query, $error = true ) {
    
        if (!is_user_logged_in()) {
            if ( is_search() ) {
                $query->is_search = false;
                $query->query_vars[s] = false;
                $query->query[s] = false;
                // to error
                if ( $error == true )
                    $query->is_404 = true;
            }
        }
    }
    
    add_action( 'parse_query', 'SearchOnlyForLoggedInUsers' );
    add_filter( 'get_search_form', create_function( '$a', "return null;" ) );
    
    

    The snippet can be added in wp-content/themes/sweetdate-child/functions.php / Note : the child theme needs to be activated.

    Cheers

    Radu

    Cheers

    Radu

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #100188
     dsniche
    Participant

    I’m not sure how to do that.

    After some Googling, here’s what I did:
    Log into WordPress, Appearance > Editor
    Check that it says “Sweetdate” in the “select theme to edit” field
    Choose functions.php
    Add the code to the file, then update

    Nothing changes so I guess I did something wrong. Help?

    If I add this code correctly, when an unregistered user tries to do a search from the search box on the home page, where does he go? What page does he see?

    #100336
     Radu
    Moderator

    Hi,

    This is an advance feature and you should know some php knowledge, as i said in a previous reply “The snippet can be added in wp-content/themes/sweetdate-child/functions.php / Note : the child theme needs to be activated.”

    It’s recommended to use sweetdate-child because you will no need to edit parent theme files.

    When a unregistered user perform a search they will see a 404 page, if you want to extend the snipped that i have provided you should make them by yourself.

    A little tip :

    For the redirection replace $query->is_404 = true; from this snippet

    COPY CODE
    
        if ( $error == true )
           $query->is_404 = true;
        }
    

    with wp_redirect( home_url() ); to redirect to home or read here if you want additional options to that function https://codex.wordpress.org/Function_Reference/wp_redirect

    Cheers

    Radu

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #100432
     dsniche
    Participant

    I found “wp-content/themes/sweetdate” but there’s no “wp-content/themes/sweetdate-child”. Is this the right folder, only named differently for some reason?

    #100568
     Radu
    Moderator

    You haven’t installed child theme, check the package with theme you will see there sweetdate-child.zip next to sweetdate.zip

    Cheers

    Radu

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #100675
     dsniche
    Participant
    This reply has been set as private.
    #100756
     Radu
    Moderator

    Hi,

    The child theme is activated ?

    Cheers

    Radu

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #100883
     dsniche
    Participant

    Hi Radu, yes the child theme is activated now.

    Attachments:
    You must be logged in to view attached files.
    #100997
     Radu
    Moderator

    Ok,

    Now the code that i have provided you it should work.

    Cheers

    Radu

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #101099
     dsniche
    Participant

    It doesn’t work. Child theme is activated and I tried using your original code that leads to the 404 page. Search still leads to results page for users who are not logged in.

    #101169
     Radu
    Moderator

    Hi,

    If you have performed a search as guest user and you have receive 404 error the snippet that i have provided you it works, you need to adapt that snippet for your needs as how i said in this reply you can replace

    COPY CODE
    
        if ( $error == true )
           $query->is_404 = true;
        }
    

    with wp_redirect( home_url() ); to redirect to home or read here if you want additional options to that function https://codex.wordpress.org/Function_Reference/wp_redirect or you can replace with your desired function but you need to have some php knowledges

    Cheers

    RAdu

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #101273
     dsniche
    Participant

    I understand it’s supposed to go to the 404 page if it works. What I meant was that the search still leads to the results page for users who are not logged in. It doesn’t work.

    #101537
     Radu
    Moderator

    Hi,

    The snippet that i have provided to you it works and it is as example but you need to have advanced php knowledges to adapt it for your needs of you can hire a developer to help to achieve your desired functionality.

    Cheers

    Radu

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #101672
     dsniche
    Participant

    I tried deactivating all plugins except Buddypress and removing all other codes from sweetdate-child/functions.php and bp-custom.php. I even removed the quick CSS from Sweetdate > Styling Options. I still can’t get the code to work. What else can I do to try and get the site as close to the way it is right out of the box without losing all my settings?

    #101738
     Radu
    Moderator

    Hi,

    For what you want to achieve you need to hire a developer, i provided you that function as guidance, our forum doesn’t cover custom development.

    Cheers

    Radu

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #101789
     dsniche
    Participant

    Ok is this something Seventh Queen can do then?

    #101896
     Andrei
    Moderator

    Hi,

    For any custom projects inquiries you can contact us at cornel@seventhqueen.com

    Cheers

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
Viewing 18 posts - 1 through 18 (of 18 total)

You must be logged in to reply to this topic.

Log in with your credentials

Forgot your details?