Forums Forums Search Search Results for 'current_query'

Viewing 10 results - 51 through 60 (of 344 total)
  • Author
    Search Results
  • #251095

    Trevor
    Participant

    Ah, I see. I do not know of a way to do what you want. It would likely mean some advanced custom PHP coding using this filter (used in the child theme functions.php file):

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    You would first have to detect if any query had been set, possibly using code like this (but it may have to be modified):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // modify the query to place the desired posts first
    }

    You would need the services of a skilled coder I would think.

    #250744

    Trevor
    Participant

    This post should help you:

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

    Or other posts from this search (some will be private, so those you cannot see, sorry):

    https://support.searchandfilter.com/forums/search/active_terms+0+name/


    Anonymous
    Inactive

    This strikes me as an easy fix but i’m just not finding the method –

    I’m writing a filter results page title like so:

    <h1 class="entry-title"><?php echo $sf_current_query->get_field_string("_sft_rugtype"); ?></h1>

    with _sft_rugtype (aka, Rug Type:) being the taxonomy we’re filtering by, this all works fine but the title gets printed as “Rug Type: [term name]” – we’re looking to exclude the taxonomy in the display so it only says the term name. My apologies if this is documented somewhere i’m struggling to find it.

    #250548

    Anonymous
    Inactive

    Hi Trevor thank you for the help- I tried adding the code to the top and replacing and it did not sort the tags alpahbetically. Where I am trying to accomplish this is the left side “Tags” filter on the resources page (https://hceg.org/resources/) before and after filtering.

    Here is the current code I updated on the search-filter/results.php file

    <?php
    /**
    * Search & Filter Pro
    *
    * Sample Results Template
    *
    * @package Search_Filter
    * @author Ross Morsali
    * @link https://searchandfilter.com
    * @copyright 2018 Search & Filter
    *
    * Note: these templates are not full page templates, rather
    * just an encaspulation of the your results loop which should
    * be inserted in to other pages by using a shortcode – think
    * of it as a template part
    *
    * This template is an absolute base example showing you what
    * you can do, for more customisation see the WordPress docs
    * and using template tags –
    *
    * http://codex.wordpress.org/Template_Tags
    *
    */

    function compare_tags_naturally($a, $b) {
    return strnatcmp($a->name, $b->name);
    }
    if ( $query->have_posts() )
    {
    ?>

    <div style=”text-align: right”>
    <?php global $searchandfilter;
    $sf_current_query = $searchandfilter->get(13622)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==””)) { } else { ?>
    Found <?php echo $query->found_posts; ?> Results,
    <?php } ?>
    Page <?php echo $query->query[‘paged’]; ?> of <?php echo $query->max_num_pages; ?></div>

    <div class=”pagination”>

    <div class=”nav-previous”><?php next_posts_link( ‘Previous’, $query->max_num_pages ); ?></div>
    <div class=”nav-next”><?php previous_posts_link( ‘Next’ ); ?></div>
    <?php
    /* example code for using the wp_pagenavi plugin */
    if (function_exists(‘wp_pagenavi’))
    {
    echo “<br />”;
    wp_pagenavi( array( ‘query’ => $query ) );
    }
    ?>
    </div>

    <?php
    while ($query->have_posts())
    {
    $query->the_post();

    ?>
    <div>
    <h2>” target=”_blank” class=”read_more_link”><?php the_title(); ?></h2>

    <?php the_excerpt(); ?>
    <?php
    if ( has_post_thumbnail() ) {
    echo ‘<p>’;
    the_post_thumbnail(“small”);
    echo ‘</p>’;
    }
    ?>
    <p><?php the_category(); ?></p>
    <?php
    $unsorted_tags = get_the_tags();
    $tags = usort($unsorted_tags, ‘compare_tags_naturally’);
    ?>
    <p><?php echo implode(‘, ‘, $tags); ?></p>
    <p><small><?php the_date(); ?></small></p>

    </div>

    <hr />
    <?php
    }
    ?>
    Page <?php echo $query->query[‘paged’]; ?> of <?php echo $query->max_num_pages; ?><br />

    <div class=”pagination”>

    <div class=”nav-previous”><?php next_posts_link( ‘Previous’, $query->max_num_pages ); ?></div>
    <div class=”nav-next”><?php previous_posts_link( ‘Next’ ); ?></div>
    <?php
    /* example code for using the wp_pagenavi plugin */
    if (function_exists(‘wp_pagenavi’))
    {
    echo “<br />”;
    wp_pagenavi( array( ‘query’ => $query ) );
    }
    ?>
    </div>
    <?php
    }
    else
    {
    echo “No Results Found”;
    }
    ?>

    #249704

    Trevor
    Participant

    You first need to find out where the data is, and to do so you need to examine the filter array:

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

    This will print that array to the screen. From that you would need to use code LIKE this:

    echo $sf_current_query['_sft_category']['active_terms'][0]['name']

    This would echo out the first Category term. You will need to write a similar line, for example:

    echo $sf_current_query['_sfm_industries']['active_terms'][0]['name']

    #249703

    Trevor
    Participant

    In the form setting, which Display Results method are you using?

    From your question, I assume that you are not using our Shortcode Display results method. If you are using some form of page builder, what you want will not currently be possible (but we hope to make it so in V3, due in a few months).

    If you are using the As and Archive, Post Type Archive or some of the methods that use the Custom method, and if you have access to a PHP template that is used in the display of the page/results, then it is, with good PHP skills, to code what you want. You would need to know what the results array variable is named if you are using a theme PHP template. It is often named $query or $wp_query, but can be anything the developer of the theme wants.

    For example, to display the number of results, code LIKE this would do that:

    Found <?php echo $query->found_posts; ?> Results

    Code LIKE this (change the ID number to be that of your form) would display the text search term, for example:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(12345)->current_query();
    if (!$sf_current_query->get_search_term()=="") {
      echo '<div>Displaying: ' . $sf_current_query->get_search_term() . '</div>'; 
    }

    You would want these code snippets placed inside the block that is being refreshed with Ajax (the ‘Ajax Container’).


    Anonymous
    Inactive

    My S&F is entirely filtering on ACF fields as post meta results.

    I’d like to display the selected search terms, however there seems to be a difference in how to get these vs more standard fields like category.

    For example:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1526)->current_query();
    echo $sf_current_query->get_field_string("_sft_category");

    gives the expected result, but changing the argument in the third line to be a custom field using the name that appears in the url bar(?_sfm_work_type=26-%2C-27&_sfm_industries=14-%2C-15) doesn’t give any results, even though the filter works fine.

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1526)->current_query();
    echo $sf_current_query->get_field_string("_sfm_industries");

    Is there a change in method to get those fields?

    #249466

    In reply to: Product finder


    Trevor
    Participant

    It would require custom coding in the template for the page, around the part that shows the results loop.

    Something like this in PHP (this example assumes you are using our Shortcode method, which in turn uses a template named results.php):

    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 products output code here
    }

    The ID number must match that of your form. My message line would simply not be there at all.

    Note, if you are using a page builder, this method may not be possible.

    #249230

    Trevor
    Participant

    Whoops:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(102003)->current_query();
    if (!$sf_current_query->get_search_term()=="") {
      echo '<div>' . $sf_current_query->get_search_term() . '</div>'; 
    }
    #249221

    Trevor
    Participant

    Ah. What about this (I did get the form ID number right, yes?):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(102003)->current_query();
    if (!$sf_current_query->get_search_term()=="") {
      echo '<div>$sf_current_query->get_search_term()</div>'; 
    }
Viewing 10 results - 51 through 60 (of 344 total)