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?
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).
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 );
1. You code the SFID (which is the ID number of the form), like this (assuming the form ID is 1234, but you will need to change that to match the ID of your form):
Our function (sf_edit_query_args) passes the sfid itself.
2. This method works irrespective of the Display Results Method you use in the form.
3. That is your choice, depending on how you want your site to work, but again this method works irrespective of the Ajax setting in the form.
4. No need to rebuild the cache.
5. Not really. There may be a monitor function on your server to show if it is being used.
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)?
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:
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.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
*Other cookies used for logging in and cart functions will only be used when you use those features and cannot be disabled.
If you disable these cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
3rd Party Cookies
This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
Please enable Strictly Necessary Cookies first so that we can save your preferences!