Forums Forums Search Search Results for 'current_query'

Viewing 10 results - 31 through 40 (of 344 total)
  • Author
    Search Results
  • #256885

    In reply to: No search results


    Trevor
    Participant

    I apologise for the delay Jens, I ran out of time yesterday.

    If you haven’t already done so, can you follow this guide:

    https://searchandfilter.com/documentation/search-results/using-a-shortcode/

    In particular, follow the instructions in the Customising section.

    That will give you a results.php file you can edit, in a sub-folder named search-filter in your theme folder.

    Would you want to show that after you search? My guess is yes. So, look for this code in the results.php template file:

    Found <?php echo $query->found_posts; ?> Results<br />
    Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />

    And change that to (I think this will work):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(30408)->current_query();
    if (!((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==""))) {
    	Found <?php echo $query->found_posts; ?> Results<br />
    	Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
    }

    You can change anything else you want also. For example, to make the pagination look nicer, install the free WP-PageNavi plugin and delete these lines:

    <div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div>
    <div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div>
    
    #256352

    Trevor
    Participant

    You would need to code some PHP. As you are using the Shortcode display results method, start with this guide (if you have not already):

    https://searchandfilter.com/documentation/search-results/using-a-shortcode/#customising-the-results

    To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:

    https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/

    … and this search will give similar threads I think:

    https://support.searchandfilter.com/forums/search/sf_current_query+get_array

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

    #256340

    Trevor
    Participant

    The code we would normally recommend, so you may need to modify this, or may indeed have used this, is:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1045)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // the unfiltered posts output code here 
    } else {
      // the current (filtered) posts output code here
    }
    #256329

    Anonymous
    Inactive

    Amazing, this works perfectly, thank you!!

    I’m using it to run a function to offset the number of posts on the first page, but only if the page is outputting the default/unfiltered loop. Is this the best way to check that?

    global $searchandfilter;
    $filtered = $searchandfilter->get(1045)->current_query()->is_filtered();
    if ( !is_admin() && $query->is_main_query() && is_home() && $filtered != 1 ) {
    ...
    }
    #255240

    Trevor
    Participant

    The PHP to use to conditionally run code looks like this (change the ID of the form to suit):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // the current (unfiltered) posts output code here
    } else {
      // the desired (filtered) posts output code here
    }
    #254727

    In reply to: Results count


    Anonymous
    Inactive

    Trevor,

    It works.
    $sf_current_query = $searchandfilter->get($id)->current_query();
    $term = $sf_current_query->get_search_term();
    $count = $wp_query->found_posts;

    Thank you,

    Christian

    #254718

    In reply to: Results count


    Trevor
    Participant

    You will not find the count in the $sf_current_query array.

    What display results method are you using?

    #254714

    In reply to: Results count


    Anonymous
    Inactive

    Trevor,

    I did try this:

    $sf_current_query = $searchandfilter->get($id)->current_query();
    $term = $sf_current_query->get_search_term();
    $count = $sf_current_query->found_posts;

    I returns the term, but not the count. How can I get the results count from the Search and Filter query?

    Thank you,

    Christian

    #254383

    Trevor
    Participant

    Are you using our Shortcode Display Results method. If not, you would need to be using a method that uses a (simple) theme PHP template and be abel to add code like this (the ID number needs to match your form):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // the current (filtered) posts output code here
    }
    #254268

    Trevor
    Participant

    So, the logic would look something like this (the ID would match that of the search form):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // the code to display the 8-10 default houses
    } else {
      // the normal results loop code here
    }

    But, I am not sure Avada uses traditional templates, so this may be difficult to code. In the past, other Avada users have needed to use a third party grid plugin, such as this method (which does not offer the option to do as you want in this case):

    https://searchandfilter.com/documentation/3rd-party/post-grid/

Viewing 10 results - 31 through 40 (of 344 total)