-
Author
-
January 22, 2016 at 10:18 #99918dsnicheParticipant
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?
January 22, 2016 at 18:19 #100010RaduModeratorHi,
Here is a code that allows only logged in users to search.
COPY CODEfunction 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 solutionJanuary 24, 2016 at 02:27 #100188dsnicheParticipantI’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 updateNothing 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?
January 25, 2016 at 14:16 #100336RaduModeratorHi,
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 CODEif ( $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 solutionJanuary 25, 2016 at 22:59 #100432dsnicheParticipantI 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?
January 26, 2016 at 16:31 #100568RaduModeratorYou 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 solutionJanuary 27, 2016 at 16:27 #100756RaduModeratorHi,
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 solutionJanuary 27, 2016 at 22:59 #100883dsnicheParticipantHi Radu, yes the child theme is activated now.
Attachments:
You must be logged in to view attached files.January 28, 2016 at 16:08 #100997RaduModeratorOk,
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 solutionJanuary 29, 2016 at 02:32 #101099dsnicheParticipantIt 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.
January 29, 2016 at 16:37 #101169RaduModeratorHi,
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 CODEif ( $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 solutionJanuary 29, 2016 at 23:35 #101273dsnicheParticipantI 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.
February 1, 2016 at 15:43 #101537RaduModeratorHi,
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 solutionFebruary 2, 2016 at 05:21 #101672dsnicheParticipantI 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?
February 2, 2016 at 16:26 #101738RaduModeratorHi,
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 solutionFebruary 2, 2016 at 22:57 #101789dsnicheParticipantOk is this something Seventh Queen can do then?
February 3, 2016 at 18:01 #101896AndreiModeratorHi,
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 -
AuthorPosts
You must be logged in to reply to this topic.