Search Results for 'current_query'

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

Viewing 10 results – 121 through 130 (of 385 total)
  • Author
    Search Results
  • #221016

    Anonymous
    Inactive

    hi Ross, hi Trevor,

    you guys are really supportive and i read a lot of posts on the forum. i still can’t figure out what i am trying to do alone, so i thought i would reach out.

    1 – latest WP 5.2.3
    2 – S&F Pro
    3 – ACF Pro (latest)
    4 – custom theme from scratch

    on the news search page (which is the standard posts type of WP), i am trying to do this:

    1 – allow a category filter
    2 – a search box
    3 – allow a date range filter with the terms “past month, 6 month, past year, older than 1 year”

    1 and 2, no problem. works perfectly.

    for date range, since that’s not an existing feature, i am trying to trick it to working.

    i read about the action filters, and i read about the various hooks.

    i realize that’s not something that can be done with a regular date field on Post Date.
    so i need to find another way.

    I am able to add a 'date_query' in a sf_edit_query_args function. When I hard code it like that it works just fine. But I want to give the visitor the dropdown that allows that choice.

    I tried to inject a dropdown in the form but it was being ignored by the Ajax function.
    I tried to use a dummy ACF field, called “sf-date-range” which contains the options I want for that (-1 month, -6 month, etc.) and build the date_query from that. I am able to do so with the sf_edit_query_args function, like this:

    
    /* custom search and filter query update based on date range */
    function custom_date_query_for_sf( $query_args, $sfid ) {
    	
    	global $searchandfilter;
    	
    	$sf_current_query = $searchandfilter->get(2467)->current_query();
    	$customFieldsArray = $sf_current_query->get_array();
    	$customHumanDate = $customFieldsArray["_sfm_sf-date-range"]["active_terms"][0]["value"];
    	 
    	//if search form ID = 2467 // news search, the do something with this query
    	if($sfid == 2467)
    	{
    			
    		if ($customHumanDate && $customHumanDate != NULL) { 
    
    				$query_args['date_query'] =  array(array('after' => $customHumanDate,));
    
    			} 
    		
    		echo "<pre>";
    		print_r($query_args);
    		echo "</pre>";  
    	
    	}
    
    	return $query_args;
    
    }
    
    add_filter( 'sf_edit_query_args', 'custom_date_query_for_sf', 20, 2 );
    

    however, since that ACF field is not really being used, the search returns blank since those fields aren’t checked, ever. the query is built ok, and again when I hard code it without the use of that ACF field, works fine:

    this example, hard-coded, returns exactly what’s expected (posts older than 1 year and younger than 2 years) :

    `
    Array
    (
    [paged] => 1
    [search_filter_id] => 2467
    [search_filter_override] =>
    [posts_per_page] => 10
    [post_status] => Array
    (
    [0] => publish
    )

    [category__not_in] => Array
    (
    [0] => 42
    )

    [meta_query] => Array
    (
    )

    [post_type] => post
    [orderby] => Array
    (
    [date] => DESC
    )

    [date_query] => Array
    (
    [0] => Array
    (
    [before] => -1 year
    )

    [1] => Array
    (
    [after] => -2 year
    )

    )

    )
    ‘

    so I know my query works.

    when i use the ACF field to generate the dropdown and make it all Ajax and neat, i don’t get the right results, even though I get the right query built (I have to refresh the screen to see the query, but i see it and it’s good. by the way, can I make the print_r that’s got the query printout ajaxified so that it shows me the right values on form change?)…

    I think the issue is that the ACF field I am using as a dummy dropdown generator is being read and obviously no values are in there since it’s not really being used. I tried to “unset” or “ignore” the ACF field which I only use to make it ajax and friendly…

    do you have a suggestion on how to accomplish what I am trying to accomplish? I know that v3 will allow me to make my own fields (which is what I am trying to do really here but without that) – but that’s not something I can wait on at the moment.

    i can send you a link in private if you want to see what I am doing.

    much appreciated,

    thanks — 

    Kaz

    #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!

    #220031

    Trevor
    Participant

    From your original code I would have had this:

    <?php
    /**
     * Search & Filter Pro 
     *
     * Sample Results Template
     * 
     * @package   Search_Filter
     * @author    Ross Morsali
     * @link      http://www.designsandcode.com/
     * @copyright 2015 Designs & Code
     * 
     * 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
     *
     */
    
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(233)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
    if ( $query->have_posts() )
    {
    	?>
          
    	<?php
    	while ($query->have_posts())
    	{
    		$query->the_post();
    		
    		?>
    	
    	    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		    <a href="<?php the_permalink(); ?>" alt="<?php the_title(); ?>">
    		        <h2><?php the_title(); ?></h2>
                    <?php if( get_field('summary_portfolio_description') ): ?>
                        <p><?php the_field('summary_portfolio_description'); ?></p> 
                    <?php endif; ?>		        
    		       <?php the_excerpt(); ?>
                </a>
            </article>
            
    		<?php
    	}
    
    }
    else
    {
    	echo "<span id='no-results'>No results found, please try altering your search criteria.</span>";
    }
    }
    ?>
    #219973

    Anonymous
    Inactive

    Hi Trevor,

    Thanks for the prompt reply, I’ve amended my results.php file as per your suggestion on that other post but I think I’ve done something wrong as no results show now.

    This is my code:

    if ( $query->have_posts() )
    {
    	?>
          
    	<?php
    
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(233)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
         
            
    		?>
    	
    	  Results code here.
            
    		<?php} 
    	}
    
    ?>

    Any ideas where I’m going wrong with this?

    Thanks,

    James

    #219094

    Trevor
    Participant

    That plugin, and others like it, will impact sorting in our plugin as it acts later in the WordPress page creation process. Post Types Order does have a hook you can use though, to stop it working under conditions that you set. It is discussed here:

    https://wordpress.org/support/topic/to-avoid-plugin-conflict-how-to-disable-post-type-order-for-search-pages/

    Maybe like this (in your child theme functions.php file):

    add_filter('pto/posts_orderby/ignore', 'pto_ignore', 10, 3);
    function pto_ignore( $ignore, $orderBy, $query ) {
      global $searchandfilter;
    $sf_current_query = $searchandfilter->get(12345)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
    } else {
      $ignore = TRUE;
    }
    return $ignore; 
    }

    Where 12345 is changed to the ID of your search?

    I am not sure if this is much the same, but simpler/shorter:

    add_filter('pto/posts_orderby/ignore', 'pto_ignore', 10, 3);
    function pto_ignore( $ignore, $orderBy, $query ) {
      global $searchandfilter;
    $sf_current_query = $searchandfilter->get(12345)->current_query();
    if (!((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==""))) $ignore = TRUE;
    return $ignore; 
    }
    #217681

    Anonymous
    Inactive

    I have checked every similar thread regarding this but am still stuck it seems:

    I’m trying to filter the products on my S&F form to display only those products with a certain number of ‘LIKES’.

    
      if ( $sfid == 26 ) {
        $query_args = array (
          'meta_query' => array(
            array(
              'key'       => '_likes',
              'value'     => 1,
            ),
          ),
    	  );
      }
    
      return $query_args;
    
    }
    add_filter( 'sf_edit_query_args', __NAMESPACE__.'\\user_liked_products_search_filter', 100, 2 );
    

    The function itself is running and also definitely against form ID 26. However it doesn’t appear in the S&F query it seems, here is a dump of the following:

    
     global $searchandfilter;
     $sf_current_query = $searchandfilter->get(26)->current_query();
     var_dump($sf_current_query);
    
    
    object(Search_Filter_Active_Query)[2753]
      public 'sfid' => int 26
      private 'is_set' => boolean true
      private 'query_array' => 
        array (size=0)
          empty
      private 'form_fields' => 
        array (size=2)
          'search' => 
            array (size=4)
              'type' => string 'search' (length=6)
              'heading' => string '' (length=0)
              'placeholder' => string 'Search …' (length=10)
              'accessibility_label' => string '' (length=0)
          '_sft_product_cat' => 
            array (size=18)
              'type' => string 'taxonomy' (length=8)
              'input_type' => string 'select' (length=6)
              'heading' => string '' (length=0)
              'accessibility_label' => string '' (length=0)
              'all_items_label' => string '' (length=0)
              'show_count' => int 1
              'hide_empty' => int 1
              'hierarchical' => int 1
              'include_children' => int 0
              'drill_down' => int 0
              'sync_include_exclude' => int 1
              'combo_box' => int 1
              'no_results_message' => string '' (length=0)
              'operator' => string 'and' (length=3)
              'order_by' => string 'default' (length=7)
              'order_dir' => string 'asc' (length=3)
              'exclude_ids' => string '' (length=0)
              'taxonomy_name' => string 'product_cat' (length=11)
      private 'query_str' => int -1
      public 'plugin_slug' => string 'search-filter' (length=13)
      public 'form_settings' => 
        array (size=37)
          'use_template_manual_toggle' => int 1
          'enable_taxonomy_archives' => int 0
          'enable_auto_count' => int 0
          'auto_count_refresh_mode' => int 1
          'auto_count_deselect_emtpy' => int 0
          'template_name_manual' => string 'search.php' (length=10)
          'page_slug' => string '' (length=0)
          'post_types' => 
            array (size=1)
              'product' => int 1
          'post_status' => 
            array (size=1)
              'publish' => int 1
          'use_ajax_toggle' => int 1
          'scroll_to_pos' => string '0' (length=1)
          'pagination_type' => string 'normal' (length=6)
          'custom_scroll_to' => string '' (length=0)
          'auto_submit' => int 1
          'display_results_as' => string 'shortcode' (length=9)
          'update_ajax_url' => int 1
          'only_results_ajax' => int 1
          'ajax_target' => string '#main' (length=5)
          'ajax_links_selector' => string '.pagination a' (length=13)
          'infinite_scroll_container' => string '' (length=0)
          'infinite_scroll_trigger' => string '-100' (length=4)
          'infinite_scroll_result_class' => string '' (length=0)
          'show_infinite_scroll_loader' => int 1
          'results_per_page' => int 10
          'exclude_post_ids' => string '' (length=0)
          'field_relation' => string 'or' (length=2)
          'default_sort_by' => string '0' (length=1)
          'sticky_posts' => string '' (length=0)
          'default_sort_dir' => string 'desc' (length=4)
          'default_meta_key' => string '_um_core' (length=8)
          'default_sort_type' => string 'numeric' (length=7)
          'secondary_sort_by' => string '0' (length=1)
          'secondary_sort_dir' => string 'desc' (length=4)
          'secondary_meta_key' => string '_um_core' (length=8)
          'secondary_sort_type' => string 'numeric' (length=7)
          'taxonomies_settings' => 
            array (size=11)
              'category' => 
                array (size=2)
                  ...
              'post_tag' => 
                array (size=2)
                  ...
              'post_format' => 
                array (size=2)
                  ...
              'action-group' => 
                array (size=2)
                  ...
              'um_hashtag' => 
                array (size=2)
                  ...
              'product_type' => 
                array (size=2)
                  ...
              'product_visibility' => 
                array (size=2)
                  ...
              'product_cat' => 
                array (size=2)
                  ...
              'product_tag' => 
                array (size=2)
                  ...
              'product_shipping_class' => 
                array (size=2)
                  ...
              'ep_custom_result' => 
                array (size=2)
                  ...
          'results_url' => string 'https://dev.influxshopping.co.uk/user/admin/?profiletab=products' (length=64)
      public 'cache_table_name' => string 'wp_search_filter_cache' (length=22)
      public 'term_results_table_name' => string 'wp_search_filter_term_results' (length=29)
      public 'field_values' => 
        array (size=0)
          empty
    

    No sign of the _likes field in the query at all.

    #216800

    Anonymous
    Inactive

    Thank you for your support.

    I would like put add more information about current situation.
    1.Form 78 and Form 50 have different search form UI.

    Form 50 -> line
    Form 78 -> price, some preference etc..

    Could you please provide some solution ?

    2.what is the Active Query Object for ? where do I need to put this code ?

    <?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(1526)->current_query();
    ?>

    https://searchandfilter.com/documentation/accessing-search-data/

    Regards,

    #215861

    Anonymous
    Inactive

    I get the array on the result page using this code:
    <?php
    //Get the search term
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(154)->current_query();
    echo $sf_current_query->get_fields_html(
    array(“_sft_manufacturer”, “_sft_year”,”_sft_engine_type”,”_sft_engine_model”)
    );
    ?>
    it shows:
    manufacturers: crusader
    years: All years
    engine type: inboard
    Engine Model: All Engine Model

    So how to let it show on woocommerce new order email ?

    Thanks.

Viewing 10 results – 121 through 130 (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.