Forums Forums Search & Filter Pro Amending WP_Query for a form with a dynamic variable

Viewing 8 posts - 1 through 8 (of 8 total)
  • Anonymous
    #213626

    Hi TJ,

    On your second example, did you try adding: global $arr_product_ids within the function too? Your trying to use $arr_product_ids variable.

    
    function filter_function_name( $query_args, $sfid ) {    
        if($sfid==2978) {
    
            global $arr_product_ids;
    
            $query_args['post_product'] = $arr_product_ids;
        }    
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    
    Anonymous
    #213628

    TJ, another quick example maybe to help:

    
    function filter_function_name( $query_args, $sfid ) {    
        if($sfid==2978) {
    
         global $arr_product_ids;
    
          $query_args['tax_query'] = array(
            array(
              'key'     => 'post_product',
              'value'   => $arr_product_ids,
              'compare' => 'IN',
            ),
          );
    
        }    
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    
    Anonymous
    #213642
    This reply has been marked as private.
    Trevor
    #213645
    This reply has been marked as private.
    Anonymous
    #213653
    This reply has been marked as private.
    Ross Moderator
    #213829

    Hi Holly

    I tried your code and it didn’t affect my setup at all (it should show no results, as that taxonomy doesn’t exist in my setup…)

    So… I had to double check the WP docs as it seemed like your tax query was ok on first glance but its not.

    I tried your code swapping out taxonomies for something I had in a testing environment and it didn’t work either (its much the same as yours):

    $query_args['tax_query'] = array(
    	array(
    	'key'     => 'cptuicat',
    	'value'   => array(9),
    	'compare' => 'IN',
    	)
    );

    I checked the docs and actually it should look like I think:

    $query_args['tax_query'] = array(
    	'relation' => 'AND',
    	array(
    		'taxonomy' => 'cptuicat',
    		'field'    => 'id',
    		'terms'    => array( 9 ),
    	),
    );

    This worked for me, the ID of 9 being a taxonomy term I have…

    If you copy and paste that, and swap out what you need then I think it should work.

    Let me know how you get on.

    Thanks

    Ross Moderator
    #213831

    Actually looking at your code, it looks like your structure is for a meta_query not a tax_query 🙂

    Anonymous
    #213848

    Hi Ross,

    Ahh thank you SO SO much for looking into this for me!!! So right on your last point, doh, so sorry!

    Now updated and all working a treat, I know I’ve said it before, but such an awesome plugin!!

    Thanks again 🙂

Viewing 8 posts - 1 through 8 (of 8 total)