-
Author
-
December 9, 2016 at 02:47 #146485proteusParticipant
Hello.
As the title suggests, is there any way to exclude an entire category and any posts under that category from the ajax search function if the current user has a certain role ‘testman’.
Kind Regards
December 9, 2016 at 18:54 #146587RaduModeratorHi,
Add this function to wp-content/themes/buddyapp-child/functions.php
COPY CODEfunction sq7_altering_ajax_search($defaults){ $defaults['cat'] = '-20'; } apply_filters( 'kleo_ajax_query_args', 'sq7_altering_ajax_search');
20 represents category ID and minus sign represents remove.
Full documentation to WP Query args
https://codex.wordpress.org/Class_Reference/WP_Query#Category_ParametersCheers
R.Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionDecember 11, 2016 at 23:05 #146677proteusParticipantHello I tried this and it did not work. The results in the top search bar still return a list of posts from the category that I do not want visible.
Below is what I have added to the child theme functions.php file.
I have attached an image.
COPY CODE/** * EXCLUDE INTRAHUB CATEGORY FROM SEARCH AJAX EXCEPT FOR USERS THAT ARE ADMINS OR PROTEUS */ function sq7_altering_ajax_search($defaults){ if ( current_user_can('proteus') || ! $query->is_main_query() ) { return; } else { $defaults['cat'] = '-1230'; } } apply_filters( 'kleo_ajax_query_args', 'sq7_altering_ajax_search'); /** * EXCLUDE INTRAHUB CATEGORY FROM SEARCH EXCEPT FOR USERS THAT ARE ADMINS OR PROTEUS */ function wcs_exclude_category_search( $query ) { if ( current_user_can('proteus') || ! $query->is_main_query() ) return; if ( $query->is_search ) { $query->set( 'cat', '-1230' ); } }
Attachments:
You must be logged in to view attached files.December 12, 2016 at 19:29 #146788RaduModeratorHi,
Use this snippet instead, it should work just i’ve tested
COPY CODEfunction sq7_altering_ajax_search($defaults){ $defaults['cat'] = '-20'; return $defaults; } add_filter( 'kleo_ajax_query_args', 'sq7_altering_ajax_search');
Cheers
RHi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution -
AuthorPosts
The forum ‘General questions’ is closed to new topics and replies.