Search Results for 'current_query'

Forums › Forums › Search › Search Results for 'current_query'

Viewing 10 results – 281 through 290 (of 385 total)
  • Author
    Search Results
  • #105034

    Trevor
    Participant

    Hi

    You could use PHP to see if the results are filtered, like this (change the ID number for yours):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if (($sf_current_query->is_filtered())||($sf_current_query->get_search_term()!="")) {
      // do something that identifies a search has been made (set some CSS, ...)
    }
    // your normal template code here
    
    #104843

    Anonymous
    Inactive

    I have two forms that I’d like to work together. The search form sits in the header and is only a search input (sfid 5729). The Filter form sits in the sidebar and has dropdowns for 3 custom taxonomies plus a from and to date (sfid 5727). They both are set to display in archive.php. The search form will use a url such as this, https://boardofednew.webdev.idaho.gov/search/?_sf_s=test.

    The archive.php sidebar is implemented with content aware sidebars plugin and the sf widget for this filter form is set to display in it (5727).

    So when I access the current press releases from the menu using url https://domainnamehere/resources/?_sft_resourcetype=press-releases and archive.php the filter form (5727) displays properly along with the filtered results for press releases. However, when I use the search form from the header (5729), it displays search results properly using archive.php, but it does not display the filter form (5757) in the sidebar. My intent is to return the search results for the term, then filter it further with the form in the sidebar. Code for archive.php follows:

    ‘
    <?php
    /**
    *
    * Description: Generic Index Page
    *
    * Used to display archive-type pages if nothing more specific matches a query.
    * For example, puts together date-based pages if no date.php file exists.
    *
    * If you’d like to further customize these archive views, you may create a
    * new template file for each one. For example, tag.php (Tag archives),
    * category.php (Category archives), author.php (Author archives), etc.
    *
    * @link https://codex.wordpress.org/Template_Hierarchy
    *
    * @package FoundationPress
    * @since FoundationPress 1.0.0
    */
    ?>
    <?php get_header(); ?>

    <main id=”main” class=”body-content row column” role=”main”>
    <?php get_template_part(‘template-parts/breadcrumbs’); ?>
    <div class=”medium-8 columns”>
    <header class=”page-header”>
    <?php
    global $searchandfilter;
    $sf_current_query_1 = $searchandfilter->get(5279)->current_query(); // 5279 is search input only
    $search_term = $sf_current_query_1->get_search_term();
    $sf_current_query_2 = $searchandfilter->get(5277)->current_query(); // 5277 is custom taxonomy filter input only
    $sarr = $sf_current_query_2->get_array();
    $fromDate = $sarr[_sf_post_date][active_terms][0][value] ;
    $toDate = $sarr[_sf_post_date][active_terms][1][value];
    $type = $sf_current_query_2->get_field_string(“_sft_resourcetype”);
    if ($type) {
    $type = substr($type, strpos($type, “:”) + 1);
    }
    $topic = $sf_current_query_2->get_field_string(“_sft_primarytopic”);
    if ($topic) {
    $topic = substr($topic, strpos($topic, “:”) + 1);
    }
    $audience = $sf_current_query_2->get_field_string(“_sft_audience”);
    if ($audience) {
    $audience = substr($audience, strpos($audience, “:”) + 1);
    }
    if ($search_term) {
    $type = “Search Results”;
    }
    echo ‘<h1>’ . $type . ‘</h1>’;
    echo ‘<h2 class=”subheader”>’ . $topic . ” / “. $audience . ‘</h2>’;
    echo ‘<p class=”small”>Note: Select date range or change resource, topic or audience as needed.</p>’;
    ?>
    </header><!– .page-header –>
    <?php if (have_posts()) : ?>
    <section <?php post_class(); ?> >
    <?php while (have_posts()) : the_post(); ?>
    <?php get_template_part( ‘template-parts/content’, get_post_format() ); ?>
    <?php endwhile; ?>
    <?php else : ?>
    <?php get_template_part( ‘template-parts/content’, ‘none’ ); ?>
    </section>
    <?php endif; // End have_posts() check. ?>
    <?php /* Display navigation to next/previous pages when applicable */ ?>
    <?php if ( function_exists( ‘foundationpress_pagination’ ) ) { foundationpress_pagination(); } else if ( is_paged() ) { ?>
    <nav id=”post-nav”>
    <div class=”post-previous”><?php next_posts_link( __( ‘← Older posts’, ‘foundationpress’ ) ); ?></div>
    <div class=”post-next”><?php previous_posts_link( __( ‘Newer posts →’, ‘foundationpress’ ) ); ?></div>
    </nav>
    <?php } ?>
    </div>
    <?php get_sidebar(); ?>
    </main>
    <?php get_footer(); ?>
    ‘

    #103879

    Anonymous
    Inactive

    Hey!

    So the post “Customize initial results” was really helpful, however is it possible to display a random list of results where “// your holding template code here” is at?

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // your holding template code here
    } else {
      // your normal template code here
    }

    Thanks!

    #103704

    Trevor
    Participant

    If you have access to the PHP template files, you can use something like this (change the ID for your form ID):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // your holding template code here
    } else {
      // your normal template code here
    }
    #102134

    Trevor
    Participant

    With the shortcode method, the URL re-write is not possible (it is possible only with The Post Type Archive/WooCommerce Display Results Method). This is a feature planed for V3 (being written now, release later in 2017).

    You can access the current query by adding code to the results.php file.

    I am unable to code this for you, but if you search the forum for this string sf_current_query, you will find some examples.

    #98807

    Anonymous
    Inactive

    Wooo, that got it. Thank you for your patience.

    For anyone else with this issue please see my code below. Probably not perfect but it works. 🙂

    // Exclude the default range values from the search as they are meaning the search returns no results
    
    function remove_default_range( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==25 && $query_args)	{
    		if((isset($query_args['meta_query']))&&(is_array($query_args['meta_query']))) {
    			global $searchandfilter;
    			$sf_current_query = $searchandfilter->get(25)->current_query()->get_array();
    			/* echo "<pre>";
    			print_r($sf_current_query);
    			echo "</pre>";*/
    
    			echo $sf_current_query['_sfm_minimum_per_round'][0]['value'];
    
    			if($sf_current_query['_sfm_minimum_per_round'][0]['value'] == '0' && $sf_current_query['_sfm_minimum_per_round'][0]['value'] == '50000') {
    				unset($sf_current_query['_sfm_minimum_per_round']);
    			}
    
    			if($sf_current_query['_sfm_minimum_per_season'][0]['value'] == '0' && $sf_current_query['_sfm_minimum_per_season'][0]['value'] == '1000000') {
    				unset($sf_current_query['_sfm_minimum_per_season']);
    			}
    
    		}			
    	}
    
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'remove_default_range', 20, 2 );
    #98769

    Trevor
    Participant

    It is a while since I looked at the array, but I think I did something like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(25)->current_query()->get_array();
    echo "<pre>";
    print_r($sf_current_query);
    echo "</pre>";
    #97498

    Trevor
    Participant

    This is not so easy, as it would the use of PHP around that grid, and I do not think VC can do that. This is how that is done in PHP:

    You can show them nothing (or a custom message) using this type of PHP code (change the number 1234 for the ID number of your search form and change the line echo ‘<div>Nothing to see here folks!</div>’; for whatever you want before the filter is used instead of the results – or remove for nothing at all):

    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 {
      // your VC Grid here
    }

    As I say, I am not sure how you can do that though.

    #95975

    Anonymous
    Inactive

    I found some workaround, to display currently selected value:

    $tmp = $sf_current_query->get_array();
    echo $tmp["_sfm_character"]["active_terms"][0]["name"];
    

    But it may be a bug in get_field_string method from documentation, which is not working in my case:

    echo $sf_current_query->get_field_string("_sfm_character");

    #95973

    Anonymous
    Inactive

    Sorry for the mistake, I mean echo $sf_current_query->get_field_string("_sft_category"); with t

    I did things as in the documentation, but cant output any _sfm filters

Viewing 10 results – 281 through 290 (of 385 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.