Hiding content (e.g., ) conditionally if search has been performed

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Hiding content (e.g., ) conditionally if search has been performed

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 7 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #44761
    cshiels
    cshiels
    Participant

    Hi,

    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!

    #44764
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #44794
    cshiels
    cshiels
    Participant

    Hi,

    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!

    #44805
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    In 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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.