Forums › Forums › Search & Filter Pro › Dynamically update Results URL
- This topic has 3 replies, 3 voices, and was last updated 9 months, 1 week ago by Anonymous.
-
Anonymous(Private) August 17, 2019 at 11:33 am #219187
Hi,
Is there a hook/filter which I can use in order to dynamically update the Results URL of a form?
Each ‘shop’ on my website displays a users products via the form. However, each shop is obviously at a different url:
example.com/shop/amazing-lamps
example.com/shop/johns-tablesCurrently it’s set to: example.com/shop/amazing-lamps
If I do a form search on: example.com/shop/johns-tables it will redirect be back to the above url instead for the results.Therefore the URL needs changing on load. I know this is not a normal use-case but if I have a hook/filter to pass data to, to change that results url, that’ll work for me.
Anonymous(Private) August 17, 2019 at 12:00 pm #219188I realised that the results_url is simply a piece of post meta, meaning I could just:
Grab the form ID
Provide the meta key to update
Build a new url baseif ( $sfid == 29 ) {
// Dynamically update the search-and-filter results url.
$meta_key = ‘_search-filter-results-url’;
$results_url = home_url() . ‘/’ . ‘shop/’ . $store_user->data->user_nicename;update_post_meta( $sfid, $meta_key, $results_url );
}This works great, however just thinking if it’s suitable. If 10 people load a different shop url all at once, that post meta is going to rapidly change.
Anyway just providing my solution so far and open to thoughts ideas if needed.
Trevor(Private) August 19, 2019 at 1:52 pm #219226I don’t know if it helps, but this filter:
https://searchandfilter.com/documentation/action-filter-reference/#modify-urls
Anonymous(Private) March 19, 2024 at 11:16 am #288374Provided by Stefan
In case someone else runs into this problem, this works to add the form to multiple pages:function my_set_sf_resultsURL( $url, $sfid) {
$url = get_permalink();
return $url;}
add_filter( ‘sf_results_url’, ‘my_set_sf_resultsURL’, 10, 2 ); -
AuthorPosts