Forums Forums Search Search Results for 'current_query'

Viewing 10 results - 101 through 110 (of 344 total)
  • Author
    Search Results
  • #225392

    Trevor
    Participant

    You could test for filtering like this, but you need to code it for the ID number of your form (replace 2611):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(2611)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // do the theme pagination 
    } else {
      // do not do theme pagination
    }

    Maybe the else part is not needed in your case?

    #224034

    Trevor
    Participant

    Possibly, but you will need to figure where to put this code:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(2611)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your current results template code here - the if have posts bit.
    }
    #223272

    Trevor
    Participant

    Such functionality would be within the scope of the theme and the template in use. Other than when the shortcode method is being used, our plugin has no direct control over your required behavior.

    The coding required would look something like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(85204)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your current results template code here
    }

    Where the ID number (85204) would need to be whatever ID number your form is.

    #223002

    Trevor
    Participant

    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.

    You could temporarily use this code in your results template to display the full filter array so that you can work out the exact array part that holds the data you want:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query,true),'</pre>';
    ?>

    Where the ID needs to match that of your form.

    #222988

    Anonymous
    Inactive

    I want to do some custom formatting depending on the used filters… I tried this:
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(69991)->current_query();
    echo $sf_current_query->get_fields_html(
    array(“_sfm_mk_quelle_affiliate_shop”),
    $args
    );

    … and: echo $sf_current_query->get_field_string(“_sfm_mk_quelle_affiliate_shop”);

    And took the field name from my search url:
    https://miriamkreativ.de/material?_sfm_mk_quelle_affiliate_shop=Creativ-Discount

    But there is nothing shown unfortunately…

    I tried one more thing (displaying the searchg term):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(69991)->current_query();
    echo $sf_current_query->get_search_term();

    … and this works for me. So please can you help me with the first example, showing / getting the chosen “affiliate shop”-option?

    #222869

    Trevor
    Participant

    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.

    You could use this to display the filter array:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query,true),'</pre>';
    ?>

    Where the ID needs to match that of your form.


    Trevor
    Participant

    That will be a function from your theme to see if a standard WordPress text search has been made, which indeed would be required to remove. Make sure you are using a child theme and name this file differently, and point our search to use this new file as the template.

    Our plugin, if you want to make a similar check if a search has been made, would use code like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(85204)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your current results template code here
    }

    Where the IF condition is set to display a different message if no search has been made (you can obviously change what it says, including adding HTML etc). Laos, change the ID number 85204 to whatever ID number our form is.

    #220260

    Anonymous
    Inactive

    Yes,

    I’m trying to figure it out. But all what I try it also removes the term.

    Like, if it is “activity: ski jobs” it ends with “jobs”

    Using this code:

    <?php echo $sf_current_query->get_field_string(“_sft_activities”); ?> jobs

    Thank you in advance!

    #220252

    Anonymous
    Inactive

    Ok got it:

    <?php echo $sf_current_query->get_field_string(“_sft_activities”); ?> jobs

    But it displays like this activities: ski jobs

    How can I remove the “activities:”

    Thanks again for your time!

    #220250

    Anonymous
    Inactive

    Thanks for the response.

    I’ve done that but it doesn’t work:

    <?php
    //grab the active query from our search form
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(3959)->current_query();
    ?>
    <h1 class=”hjobs”><?php echo $sf_current_query; ?> jobs</h1><br>

    What am I doing wrong?

    Thanks!

Viewing 10 results - 101 through 110 (of 344 total)