Search Results for 'function sf_edit_query_args'

Forums › Forums › Search › Search Results for 'function sf_edit_query_args'

Viewing 10 results – 11 through 20 (of 141 total)
  • Author
    Search Results
  • #269505

    Anonymous
    Inactive

    Hi Trevor,

    I have Elastic search setup on server and working (I tested it with different queries). I also installed ElasticPress plugin. I would like now to integrate it with S&F. I read these two posts:
    https://support.searchandfilter.com/forums/topic/algolia-vs-elastic-search-vs-search-filter-pro/
    https://support.searchandfilter.com/forums/topic/working-with-elasticpress-elasticsearch/

    But could you please give more details how to use the sf_edit_query_args?

    1) I am putting it in functions.php of the child theme but how the sfid is passed to it (is there a way to make sure it is passed correctly to the function)?

    2) I am using for Display Results “Using shortcode”, and I am customising the results as mentioned here:
    https://searchandfilter.com/documentation/search-results/using-a-shortcode/#customising-the-results
    should I use another Display results method?

    3) I am using “Load results using Ajax”, should I disable it?

    4) should I rebuild the cache of S&F after adding the above code to functions.php?
    (Note I was using Relevanssi before but I disabled it now).

    5) Is there a way to test that the s&F is using ElasticPress?

    Thanks,
    Ahmed

    #267895

    In reply to: Wrong attribute order


    Trevor
    Participant

    There is not an easy way to do this. You would need use this filter in some code that you would insert in your child theme functions.php file:

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

    As there are only four values, the easiest code would be to create a new array for that field and return that array to the form. This forum search should yield some code snippets:

    https://support.searchandfilter.com/forums/search/function+sf_edit_query_args/

    #266545

    Anonymous
    Inactive

    Hello,

    I wanted to know if the Post Meta – Date field was compatible with the ACF Datetime field?
    I set the “Date Input Format” option to YYYYMMDD (ACF) but it doesn’t work.

    If not, am I forced to split the date and the time?

    I would like to avoid for my meta_query in “sf_edit_query_args” function:

    function filter_function_name( $query_args, $sfid ) {
    	if( $sfid == 73 ) {
    		$now = current_time('Y-m-d H:i:s');
    
    		$query_args['meta_query'] = array(
    			array(
    				'key'		=> 'live_datetime',
    				'value'		=> $now,
    				'compare'	=> '>',
    				'type'		=> 'DATETIME',
    			)
    		);
    	}
    
    	return $query_args;
    }
    add_filter('sf_edit_query_args', 'filter_function_name', 20, 2);

    Thanks in advance!

    #264344

    Anonymous
    Inactive

    Hi,

    I need to filter the query, I need to get a filter that returns posts with meta “price” higher than value that user has filtered. I have tried this code, but is not working. Can you help me please?

    function filter_function_name( $query_args, $sfid ) {

    if($sfid==858){

    if(isset($_GET[‘_sfm_m2_from’]) && !isset($_GET[‘_sfm_price_from’])){

    $query_args[‘meta_query’] = array(
    array(
    ‘key’ => ‘m2_from’,
    ‘value’ => $_GET[‘_sfm_m2_from’],
    ‘compare’ => ‘>=’,
    ‘type’ => ‘NUMERIC’,
    ),
    );

    }

    if(isset($_GET[‘_sfm_price_from’]) && !isset($_GET[‘_sfm_m2_from’])){

    $query_args[‘meta_query’] = array(
    array(
    ‘key’ => ‘price_from’,
    ‘value’ => $_GET[‘_sfm_price_from’],
    ‘compare’ => ‘>=’,
    ‘type’ => ‘NUMERIC’,
    ),
    );

    }

    if(isset($_GET[‘_sfm_m2_from’]) && isset($_GET[‘_sfm_price_from’])){

    $query_args[‘meta_query’] = array(
    ‘relation’ => ‘AND’,
    array(
    ‘key’ => ‘m2_from’,
    ‘value’ => $_GET[‘_sfm_m2_from’],
    ‘compare’ => ‘>=’,
    ‘type’ => ‘NUMERIC’,
    ),
    array(
    ‘key’ => ‘price_from’,
    ‘value’ => $_GET[‘_sfm_price_from’],
    ‘compare’ => ‘>=’,
    ‘type’ => ‘NUMERIC’,
    ),
    );

    }

    }

    return $query_args;
    }
    add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 20, 2 );

    Regards

    #263751

    Anonymous
    Inactive

    Hallo,

    We have a piece of code that checks for a custom query string added in the url from another page.

    Our code that works:

    
    function filter_shop_tags($query_args, $sfid) {
        if ($sfid==112 && isset($_GET['shop-tag']) && !empty($_GET['shop-tag'])) {
            $query_args['tax_query'] = array(
                array(												 
                    'taxonomy' => 'shop_tag',												 
                    'field'    => 'slug',											 
                    'terms'    => array( $_GET['shop-tag'] ),											 
                ),
            );
        }
    
        return $query_args;
    }
    add_filter('sf_edit_query_args', 'filter_shop_tags', 20, 2);
    

    The anchor from another page is example.com/shops/?shop-tag=exampleTag.

    On the shops page we have the S&F filter. (Which is correctly filtered with the function). But when we try to active another filter with S&F. Another taxonomy for example it remove the ?shop-tag query string and turns into example.com/shops/?shop-taxonomy=exampleTax, but my wish would be: example.com/shops/?shop-tag=exampleTag&shop-taxonomy=exampleTax

    regards

    #263371

    Anonymous
    Inactive

    I already figured out the solution not via the UI, but with the filter function and query args…

    Maybe it helps someone 🙂

    function filter_function_name( $query_args, $sfid ) {
    
    // your filter pro ID
    if($sfid==123) {
    //modify $query_args here before returning it
    $query_args['meta_query'] = array(
    'relation' => 'OR',
    array(
    'key'		=> 'field',
    'value'		=> date('Ymd'),
    'type'		=> 'DATE',
    'compare'	=> '>='
    ),
    array(
    'key'		=> 'field',
    'value'		=> '',
    'compare' 	=> 'IN'
    )
    );
    
    return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    Anonymous
    Inactive

    My search had been working fine yesterday. Today I made a few changes, then removed those changes but I cannot get this to work again: https://finigan.org/
    You will see the $query_args because I am dumping them from the edit query args filter(shown below)
    These query_args don’t seem to match what the search is set up to do. I have a CPT called Poetry Node with ACFs poet_name and poem_name and 6 kinds of node_resources(these act like categories). I have the relationship set to OR in the general settings of the Search form, query_args below say AND. Id of search is 119. Results are As an Archive using index.php. It was working but earlier today I made a duplicate of this search retaining only the poet_name in the form – everything else was the same (except the searchId). I have since deleted that Search form but I’m wondering if that messed something up. I have rebuilt the cache. I’m stumped.

    function ffp_edit_query_args( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	echo "<pre>";
    		var_dump($sfid);
    		echo "</pre>";
    	//if($sfid==204) /* poem_name search */
    	//{
    		//modify $query_args here before returning it
    		//$query_args['somearg'] = 'newvalue';
    		echo "<pre>";
    		var_dump($query_args);
    		echo "</pre>";
    	//}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'ffp_edit_query_args', 20, 2 );
    #260220

    Anonymous
    Inactive

    I was able to fix my issue. Here is my code snippet in case anyone runs into the same issue…

    function set_user_di( $query_args, $sfid ) {
      //if search form ID = 225, the do something with this query
      $nam_options = get_option( 'nam_options' );
      $inventory_form_id = (int)$nam_options['my_inventory_form_id_number'];
    
    	if ( is_user_logged_in() && $sfid==$inventory_form_id ) {
        if ($query_args['meta_query']) {
          array_push($query_args['meta_query'], array(
            'key' 		=> 'owner',
            'value'		=> get_current_user_id(),
            'compare' 	=> '=',
          ));
        } else {
          $meta_query = array(
            array(
              'key' 		=> 'owner',
              'value'		=> get_current_user_id(),
              'compare' 	=> '=',
            ),
          );
    
          $query_args = $meta_query;
        }
      }
    
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'set_user_di', 20, 2 );
    #259361

    Trevor
    Participant

    Ordering is (normally) handled within our plugin, so any query arguments you set for ordering may be ignored/overridden. Instead, you would need to add them using this filter:

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

    I am not sure if that would work, but this forum search should yield some code snippets:

    https://support.searchandfilter.com/forums/search/orderby+function+sf_edit_query_args/

    #257057

    Anonymous
    Inactive

    <?php
    if ( ! defined( ‘ABSPATH’ ) ) { exit; }

    if ( ! isset( $content_width ) ) $content_width = 1280;

    function skelementor_init() {

    add_theme_support( ‘title-tag’ );
    add_theme_support( ‘post-thumbnails’ );
    add_theme_support( ‘automatic-feed-links’ );
    add_theme_support( ‘title-tag’ );
    add_theme_support( ‘html5’, array( ‘search-form’, ‘comment-form’, ‘comment-list’, ‘gallery’, ‘caption’ ) );
    add_theme_support( ‘custom-logo’, array(
    ‘width’ => 260,
    ‘height’ => 100,
    ‘flex-height’ => true,
    ‘flex-width’ => true,
    ) );
    add_theme_support( ‘custom-header’ );
    add_theme_support( ‘woocommerce’ );
    add_post_type_support( ‘page’, ‘excerpt’ );

    register_nav_menus(
    array( ‘main-menu’ => __( ‘Main Menu’, ‘skelementor’ ) )
    );

    load_theme_textdomain( ‘skelementor’, get_template_directory() . ‘/languages’ );
    }
    add_action( ‘after_setup_theme’, ‘skelementor_init’ );

    function skelementor_comment_reply() {
    if ( get_option( ‘thread_comments’ ) ) { wp_enqueue_script( ‘comment-reply’ ); }
    }
    add_action( ‘comment_form_before’, ‘skelementor_comment_reply’ );

    function skelementor_scripts_styles() {
    wp_enqueue_style( ‘skelementor-style’, get_stylesheet_uri() );
    }
    add_action( ‘wp_enqueue_scripts’, ‘skelementor_scripts_styles’ );

    function skelementor_register_elementor_locations( $elementor_theme_manager ) {
    $elementor_theme_manager->register_all_core_location();
    };
    add_action( ‘elementor/theme/register_locations’, ‘skelementor_register_elementor_locations’ );

    function price_range_on_save( $post_id ) {
    $post_type = ‘share’; //custom post type for events

    //Check if we are saving correct post type
    if( get_post_type( $post_id ) != $post_type)
    return;

    //Check it’s not an auto save routine
    if( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE )
    return;

    // get the price of the post. This assumes that the price is a number and has no currency symbol or thousands separator
    $post_price = get_post_field (‘price’, $post_id);
    // set an empty default string
    $post_price_text = “”;
    // set the price text label to match the price
    if ($post_price) {
    switch($post_price) {
    case ( $post_price <= 100 ):
    $post_price_text = “0-100 kr”;
    break;
    case ( ($post_price > 100) && ($post_price <= 250) ):
    $post_price_text = “101-250 kr”;
    break;
    default:
    $post_price_text = “250 kr and up”;
    }
    }

    // update the price choice
    update_field( ‘post_price_text’, $post_price_text );
    }
    add_action(‘save_post’, ‘price_range_on_save’);

    /////////
    $roots_includes = array(
    ‘lib/extras.php’,
    ‘lib/scripts.php’,
    ‘lib/ajax.php’,
    ‘lib/post-types.php’,
    ‘lib/init.php’,
    ‘lib/utilities.php’,
    ‘lib/acf.php’,
    // ‘lib/custom-fields.php’,
    // ‘lib/custom-fields/category.php’,
    // ‘lib/custom-fields/footer.php’,
    // ‘lib/custom-fields/post.php’,
    );

    foreach ($roots_includes as $file) {
    if (!$filepath = locate_template($file)) {
    trigger_error(sprintf(__(‘Error locating %s for inclusion’, ‘roots’), $file), E_USER_ERROR);
    }

    require_once $filepath;
    }
    unset($file, $filepath);

    // CUSTOM FILTER // Add author of the current post (SPELTIPS)
    add_action( ‘elementor/query/from_same-author’, function( $query ) {
    // The author of the current post
    $author_id = get_the_author_meta(‘ID’);
    $query->set( ‘author’, $author_id );
    } );

    // CUSTOM FILTER // Add Speltips from same expert on EXPERT page
    add_action( ‘elementor/query/spel-from-same-expert’, function( $query ) {
    // The author of the current post

    $author_id = get_field( ‘wp_authors’ );

    $query->set( ‘author’, $author_id );
    } );

    add_action( ‘elementor/query/shares-from-current_author’, function( $query ) {
    // The author of the current post

    $author_id = get_the_author_meta(‘ID’);

    $expert_id = get_field( ‘expert’, ‘user_’ . $author_id );

    if( is_array( $expert_id ) ) $expert_id = $expert_id[ ‘ID’ ];

    $meta_query = $query->get( ‘meta_query’ );

    if( ! is_array( $meta_query ) ) $meta_query = [];

    $meta_query[ ‘expert_id’ ] = [
    ‘key’ => ‘expert’,
    ‘compare’ => ‘==’,
    ‘value’ => $expert_id,
    ];

    $query->set( ‘meta_query’, $meta_query );
    } );

    // CUSTOM FILTER // Add ANDELAR (SHARES) from same expert on EXPERT page
    add_action( ‘elementor/query/andelar-from-same-expert’, function( $query ) {
    // The author of the current post
    $expert_id = get_the_ID();
    $meta_query = $query->get( ‘meta_query’ );

    if( ! is_array( $meta_query ) ) $meta_query = [];

    $meta_query[ ‘expert_id’ ] = [
    ‘key’ => ‘expert’,
    ‘compare’ => ‘==’,
    ‘value’ => $expert_id,
    ];

    $query->set( ‘meta_query’, $meta_query );
    } );

    // Add Options Page
    function add_my_options_page() {
    if( function_exists(‘acf_add_options_page’) ) {
    acf_add_options_page();
    }
    }
    add_action( ‘plugins_loaded’, ‘add_my_options_page’ );

    // Don’t put anything except includes in this file
    //Pick a place for your jsons to live. We stick them into the /theme/includes/acf-json folder, but you can stick these wherever

    // change where acf json files are saved
    add_filter(‘acf/settings/save_json’, ‘jb_acf_save_json’);
    function jb_acf_save_json($path) { return get_stylesheet_directory().’/includes/acf-json’; }

    // add our custom folder to places acf json are loaded from
    add_filter(‘acf/settings/load_json’, ‘jb_acf_load_json’);
    function jb_acf_load_json($paths) { return array_merge($paths, array(get_stylesheet_directory().’/includes/acf-json’)); }

    function custom_theme_slug_filter_the_content( $content ) {
    global $wpdb;
    if(“post” == get_post_type()){
    //if(is_singular(‘posts’)){
    $requested_post_id = get_the_ID();
    $authordetails = get_field(‘acfe_author’, $requested_post_id);
    $suthorname = $authordetails[‘display_name’];
    $expert_args = array(
    ‘post_type’ => ‘expert’,
    ‘post_status’ => ‘publish’,
    ‘title’ => trim($suthorname),
    ‘orderby’ => ‘date’,
    ‘order’ => ‘DESC’
    );
    $query = new WP_Query($expert_args);
    $postid = $query->post->ID;
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $postid ), ‘full’ );
    $custom_content = ‘<div id=”ctm-img-box” class=”custom-img-box”><span class=”elementor-icon-list-icon”></span><span class=”authorname”>’.$suthorname.'</span></div>’;
    $custom_content .= $content;
    //return $custom_content;
    }else{
    $custom_content = $content;
    }
    return $custom_content;
    }
    add_filter( ‘the_content’, ‘custom_theme_slug_filter_the_content’, 1);

    function wpa_choose_ad($user_id, $expert_id) {
    $requested_post_id = get_the_ID();
    $expert_user = get_field(‘wp_authors’, $requested_post_id);
    //echo $user_id;
    $args = array(
    ‘post_type’ => ‘share’,
    ‘posts_per_page’ => 12,
    ‘orderby’ => ‘rand’,
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘expert’,
    ‘value’ => $expert_id,
    ‘compare’ => “=”
    )
    )
    );
    $the_query = new WP_Query( $args );
    //echo “

    ";
        //print_r($the_query);
        $the_ad = '<div class="elementor-container elementor-column-gap-no">';
        	$the_ad .= '<div class="element-row">';
        	$the_ad .= '<div class="elementor-widget-container elementor-widget-heading"><h4 class="elementor-heading-title elementor-size-default">MINA ANDELAR</h4></div>';
        $the_ad .= '<div class="elementor-widget-container">';	
        $the_ad .= '<div class="ecs-posts elementor-posts-container elementor-posts elementor-grid elementor-posts--skin-custom">';
        if ( $the_query->have_posts() ) {
        while ( $the_query->have_posts() ) : $the_query->the_post();
        		$title = get_the_title();
        		$url = get_permalink(get_the_ID());
    			$expert_type = get_field('type', get_the_ID());
    			$expert_shares = get_field('shares', get_the_ID());
    			$expert_price = get_field('price', get_the_ID());
    
    		$the_ad .= '<div class="share_outer_box">';
    		$the_ad .= '<div class="share_price_details">';
    		$the_ad .= '<p>'.$expert_type.'</p>';
    		$the_ad .= '<p>'.$expert_shares.' andler | '.$expert_price.' SEK</p>';
    		$the_ad .= '</div>';
    		$the_ad .= '<h2 class="custom-title elementor-heading-title elementor-size-default">'.$title.'</h2>';
    				   	
    		$the_ad .= '</div>';
        endwhile;
        }
        $the_ad .= '</div>';
        $the_ad .= '</div>';
        $the_ad .= '</div>';
        $the_ad .= '</div>';
        wp_reset_postdata();
    
        return $the_ad;
    }
    
    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 19856, the do something with this query
    	if($sfid==19856)
    	{
    		//modify $query_args here before returning it
    		// args
    			$args = array(
    				'post_type'		=> 'shares',
    				'meta_query'	=> array(
    				'relation'		=> 'OR',
    			array(
    			'key'		=> 'type',
    			'value'		=> 'Europatipset',
    			'compare'	=> 'LIKE'
    			),
    			array(
    			'key'		=> 'type',
    			'value'		=> 'Stryktipset',
    			'compare'	=> 'LIKE'
    			)
    	)
    );
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
Viewing 10 results – 11 through 20 (of 141 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.