Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Hiding content (e.g., ) conditionally if search has been performed
- This topic has 3 replies, 2 voices, and was last updated 2 years, 10 months ago by
Ernest Marcinko.
-
AuthorPosts
-
July 20, 2023 at 9:15 pm #44761
cshiels
ParticipantHi,
I’m curious if there’s some way I can make some content that appears on page load disappear once a user has entered a search or chosen a filter setting, in the case where the results load on the same page.
I know I could just hover the results box, but this isn’t really what I’m looking for.
I’ve looked through the docs and forums and kb, also tried a few things with hooks unsuccessfully.
Something like :
if( !empty( $search_args ) ){
class=hidden
}else{
class=visible
}but I can’t figure out how to check if a search was performed (which would be the $search_args)
Thanks for any advice you have!
July 21, 2023 at 8:48 am #44764Ernest Marcinko
KeymasterHi,
Thank you for the details!
If I understand correctly, you have the auto-populate feature enabled, which shows some results. Then when the user changes a filter or enters a new phrase a new search is initiated, but this time you want to exclude some results from this and all succeding queries. Is that correct?
If so, I think there is a very simple way to do it programmatically via the asp_query_args hook:
add_filter('asp_query_args', 'asp_exclude_on_non_autopopulate', 10, 1); function asp_exclude_on_non_autopopulate($args) { if ( !$args['_is_autopopulate'] ) { $args['post_not_in'] = array(1, 2, 3, 4); // Exclude posts by ID } return $args; }This code will exclude the items by IDs from the array, if the current search quers is not the auto-populate query.
July 24, 2023 at 8:32 pm #44794cshiels
ParticipantHi,
Thanks for your quick response!
This is close to what I’m looking for.I won’t have the auto-populate enabled and I will have a content div (not related to ACP) above the search bar. Then when a filter is selected or a search performed, I’d like the content div above the search bar to become hidden, without loading a different URL.
Basically when any results load, this one div above the search bar will disappear.
Thanks again!
July 25, 2023 at 12:26 pm #44805Ernest Marcinko
KeymasterIn that case you need the front-end hooks. You want to make modifications on the client side, so you can use those, they trigger on specific search events and then you can do whatever action you need to do via javascript.
-
AuthorPosts
- You must be logged in to reply to this topic.