Forums Forums Search & Filter Pro Determine is search active on Post Type Archive

Viewing 3 posts - 1 through 3 (of 3 total)
  • Anonymous
    #261737

    Hi
    On my taxonomy archive pages I have seo text and title that displays the title and the count for the archive then adds some content at the top and bottom of the listings.

    https://dev.truckpages.co.uk/trucks/for-sale/body/box/

    At the moment I hide all this information if it is not the first page (used to use is_paged but found an answer you gave elsewhere and changed this to if ( !isset($_GET[‘sf_paged’]) ) :

    This works fine, but I also do not want to show all the text if the user can carried out a search (in other words if there are any variables after the /body/box/ in the example above.

    It is not only to hide the text, but to hide the fact that the totals count in the headline will not match the search results so will look confusing to the user.

    So the query is something like… if is not first page or not have any search criteria show text else nothing.

    I tried to use your ‘Check to see if anything has been filtered’ code which returns a ‘1’ even with no criteria applied in the URL (I assume because there is a filter somewhere as we are on a taxonomy archive page (box in the above example).

    As an aside, I would like to add a count of the search results somewhere on the page in any case – is that possible?
    Thanks

    Jason

    Anonymous
    #261746

    I have worked part of this out – hoping it won’t cause me any problems…

    $expression = filter_input(INPUT_GET, '_sfm_ca-year') . $_GET['sf_paged'] ;
    			$terms = get_the_terms( $post->ID , 'body' );
    foreach ( $terms as $term ) {
    } 
    				if ( empty($expression)) :

    Still wondering about adding an accurate count though.

    Trevor
    #261833

    You can write some custom code to find the filter terms in use, but it does requires some digging to find the variable names first (especially if you allow more than once choice per field), and you can find the total results count. So, this code gets the count (but you need the query variable/array name, so it might not be $query):

    $number_of_results = $query->found_posts;

    To figure that the variables are, you need to output the array holding the filter, then make a note of the variable names. see this post:

    https://support.searchandfilter.com/forums/topic/acf-post-meta-fields-in-current_query-result/#post-249704

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