Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Filter without a (visible) form

Viewing 10 posts - 11 through 20 (of 75 total)
  • Richard Hartley
    #270801

    Hi Trevor,

    I know how to find the ID. That’s why that ID is in the code :P.

    The problem, as described, is that nothing is happening.

    The resultset is exactly the same as before, when it should be different.

    If I do a var_dump() of $query_args; I get NULL, which I take to mean the if() statement is not being triggered.

    The WPBakery post grid is set to connect to S&F, and I have chosen the form in the dropdown which matches to that form ID.

    I assume the function is correct as the only thing I’ve changed is the $sfid and the respective values in $query_args['orientation'] = 'straight';

    Why might the if() statement not be picking up the $sfid?

    Trevor Moderator
    #270803

    Is the orientation field set in the form with that value selected? From what you are saying, no value has been selected. Thinking about it, that may be the issue. That function only works after a search has been done. Otherwise query_args is empty (null).

    Richard Hartley
    #270821

    Hi Trevor,

    Yes it is. It’s set in the “Post Meta” tab, screenshot below.

    No other filters, category filters or taxonomies have been added.

    Richard Hartley
    #270823
    This reply has been marked as private.
    Trevor Moderator
    #270829

    Ah. Settings in the Post Meta tab, and the Includes/Excludes tab, do not appear in the query_args array.

    Richard Hartley
    #270898

    OK, so the way S&F works isn’t compatible with the way I want the pages to load without creating a new form for each combination of location and orientation (every UK county & city x3, and then x4 further down the line).

    Dangit. Heh. Please tell me there’s a fix for that coming in V3!

    Time for a rethink.

    So… I have a working html form with a dropdown/checkbox for location & orientation. This ties back to a single form ID on the back end. A copy of this form will sit at the top of each page.

    When the page loads, those inputs come up with the default “all”/”unchecked” selected, as you’d expect.

    In the results box below, every item in the resultset is displayed – as expected, as there are no filters.

    I can get the appropriate filter term for the dropdown/checkbox from the slug using php.

    Could I use JS to change the “selected” or “checked” value on the form inputs as appropriate, and would it automatically re-trigger the search to use the parameters I picked out using php? (assuming ajax loading and no “submit” button).

    Trevor Moderator
    #270914

    I have referred your question to the plugin developer, Ross, for his input and advice.

    Ross Moderator
    #270938

    Hi Richard

    I’m having a look through this ticket, and if I understand correctly, the first task we need to solve is how to alter the query / restrict things conditionally.

    I think we were on the right path, with using the filter sf_edit_query_args but the implementation doesn’t look right from what I can see.

    So, to explain, our filter, sf_edit_query_args is just a fancy filter for editing query args that get passed into the new WP_Query( $query_args ); we do for our queries (there is some other stuff going on, but that’s the core of it).

    What that means is, the structure of $query_args must match those of a WP_Query – fortunately, something well documented here:
    https://developer.wordpress.org/reference/classes/wp_query/

    What we need to understand first is, what type of data is orientation?

    Is it custom field / post meta? If so, we can follow the instuctions here:
    https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters

    Assuming your meta key is orientation then we can do something like:

    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 27601, the do something with this query
    	if($sfid==27601)
    	{
    		//modify $query_args here before returning it
    		$query_args['meta_key'] = 'orientation';
    		$query_args['meta_value'] = 'straight';
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    Let me know how you get on with that!

    Best

    Richard Hartley
    #270952

    Ahh.. so that’s where I’ve been going wrong – that makes sense!

    Yes – most of the fields are stored in ACF fields. So your suggestion should work on those.

    I’ll see how it goes and get back to you.

    Many thanks both for your help!

    Richard Hartley
    #271205

    Hi guys,

    Not the most elegant solution, I suspect, but I have this code correctly pulling in the right values from the slug and parsing them. In the end I opted to filter by the category of the portfolio items as that tends to be more reliable than some of the other meta.

    I’m not sure why, but even though the form is set up to return 42 results, the page only ever displays 10.

    If I add nopaging=>true, to the query I get all results.

    Of course ideally I’d like to load them via ajax as the user scrolls. Do I need to add anything extra to this query, or pass any other variables to achieve that?

    Many thanks!

    The code is here:

    function filter_function_name( $query_args, $sfid ) {
    
    global $post;
    $slug = $post->post_name;
    $sluglist = explode("-", $slug);
    $orientation = $sluglist[0];
    unset($sluglist[0],$sluglist[1],$sluglist[2]);
    $location = implode("-", $sluglist);
    
    if($sfid=="28441"){
    
    $query_args = array(
    'post_type' => 'portfolio',
    'portfolio_category' => "$orientation + $location"
    
    );
    }
    
    return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
Viewing 10 posts - 11 through 20 (of 75 total)

The forum ‘Search & Filter Pro’ is closed to new topics and replies.