I’ve solved it with some workarounds. I will post my solution for other people:
Form settings:
– configured the form display method as ‘custom’;
– added a results url of a random page (it needs to be filled);
– enabled Ajax loading and configured a div as Ajax container;
– enabled ‘make searches bookmarkable’;
– enabled Ajax pagination.
I added a filter in functions.php, so the results url for this specific form will always be overwritten with the current permalink:
function filter_function_name( $url, $sfid) {
if (get_post_field('post_name', $sfid) == 'agenda-shadow-single-post') {
$url = get_permalink();
}
return $url;
}
add_filter( 'sf_results_url', 'filter_function_name', 10, 2 );
I implemented the form in template files as following:
<?php
// retrieving the the form by using the slug
$sf_form_obj = get_page_by_path('agenda-shadow-single-post', OBJECT, 'search-filter-widget');
if ($sf_form_obj) {
$args['search_filter_id'] = $sf_form_obj->ID;
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
get_template_part('template-parts/blocks/block-activiteit');
}
} else {
?>
<div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'></div>
<?php
}
}
?>
I tried to alter the query args with the sf_edit_query_args
filter, but it didn’t work for me. So I wrote some JavaScript to modify the value of the filter of the post-type that’s currently being viewed. After that I’ve hidden the filter, so it won’t be changed by the user. I did this with a function that’s being triggered on these ajax events:
jQuery(document).on("sf:ajaxstart sf:init sf:ajaxfinish", ".searchandfilter", function () {
fillFilterOnLocation();
});