Forums › Forums › Search & Filter Pro › Multiple forms on one page + search analytics
- This topic has 15 replies, 3 voices, and was last updated 6 years, 7 months ago by Ross.
-
Anonymous(Private) March 16, 2018 at 12:42 am #166344
Hello,
I am working on a directory feature for a client and I am using S+F pro to do that. The client has requested a sidebar version and a horizontal version of the form to be present on the same page. Is it possible to get those working in sync where selections made in one form are updated in the other?
The client has also requested that the sidebar radio buttons have hide/reveal collapse functionality. Is this something you have seen before? I know its possible to modify the markup with js to achieve this but the form reloads itself whenever ajax is engaged and the functionality would stop working. Is there a js event I can attach a callback to that will allow me to perform js work once the search results have been loaded?
A js callback might also be useful for tracking search analytics when using ajax.
Thank you for the help,
Josh.Anonymous(Private) March 21, 2018 at 3:12 am #167242Thanks Trevor,
I ended up whipping up some custom javascript to get the forms ‘working together’. It’s working well so far.
I have another question about the random order feature and pagination. Is it possible to implement random ordering whilst maintaining accurate pagination? I ran into this issue initially on the archive view and solved it using a solution found here:
https://hugh.blog/2013/08/22/wordpress-random-post-order-with-correct-pagination/
I noticed that this does not work with sf pro or pages that are using sf pro and I really need it to. Currently sf pro will randomly order each page individually which effectively makes pagination useless. Is there a way around this?
Cheers,
Josh.Anonymous(Private) March 22, 2018 at 12:45 am #167512I had a few cracks but so far I haven’t been able to get it working. Here is what my current code looks like.
session_start(); add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 ); function filter_function_name( $query_args, $sfid ) { if($sfid==27339||$sfid==27361) { // Reset seed on load of initial archive page if( ! get_query_var( 'sf_paged' ) || get_query_var( 'sf_paged' ) == 0 || get_query_var( 'sf_paged' ) == 1 ) { if( isset( $_SESSION['seed'] ) ) { unset( $_SESSION['seed'] ); } } // Get seed from session variable if it exists $seed = false; if( isset( $_SESSION['seed'] ) ) { $seed = $_SESSION['seed']; } // Set new seed if none exists if ( ! $seed ) { $seed = rand(); $_SESSION['seed'] = $seed; } // Update ORDER BY clause to use seed $order_args = array( 'orderby' => 'RAND(' . $seed . ')' ); $query_args = wp_parse_args( $query_args, $order_args ); } return $query_args; }
Trevor(Private) March 22, 2018 at 7:12 am #167537I am afraid that I do not. I have not heard of anyone doing what you are attempting. IF it can be done, it would be by using that filter, but that is all I can say. WordPress does not handle the random order very well (it os not Search & Filter that does this, but WordPress).
Anonymous(Private) March 23, 2018 at 1:04 am #167833Do you at least know if I’m on the right track with the sf pagination query var?
‘get_query_var( ‘sf_paged’ )’
This should be fairly basic if I can get the syntax down. The function is relying on paged data in order to detect a refresh of the query. SF pro modifies the format of the query so I’m not sure what changes I need to make to be able to correctly manage the sf pages. Can you help me with that? If I can do that then this should be pretty straight forward.
Trevor(Private) March 23, 2018 at 10:06 am #167891You could test what you get from that function by echoing what it contains on to the page inside some identifying HTML so it stands out and is easy to spot.
I can refer it to the developer to ask him if he can cats an eye over your code, if you wish?
Anonymous(Private) March 24, 2018 at 9:19 am #168110Hi Trevor,
I have been doing exactly that and I think I have gotten pretty close to getting this solved but I have hit another snag. I think the only problem I have now is that I cant get the session variable to stick whilst using the filter you supplied. The filter might be running before the session data is loaded or the session data may not work inside of the filter. I might need to find another method of storing the rand seed variable into user cookies or something similar.
I have modified the sf form and taken it off rand. I am now using the function to apply the random order, which means I can control the incoming arguments whereas I couldnt before. I am collecting the query args from the filter then assessing the paged data and at that point will create or reuse the random seed session variable. The only problem I have is the filter is not detecting the stored session data, I assume this is because the filter is running before the session data is loaded? that would explain why its being reset every time.
I feel like is pretty close to working and would really appreciate if you could ask your developer to take a quick look at the function. This is what I have so far:
session_start(); add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 ); function filter_function_name( $query_args, $sfid ) { if($sfid==27339||$sfid==27361) { // Detect first page and reset seed if( ! $query_args['paged'] || $query_args['paged'] == 0 || $query_args['paged'] == 1 ) { ?><p>first page<p><?php if( isset( $_SESSION['seed'] ) ) { unset( $_SESSION['seed'] ); ?><p>seed unset<p><?php } } else { ?><p>not first page<p><?php } ?><p>session seed value: <?php print_r($_SESSION['seed']);?></p><?php // Get seed from session variable if it exists and store it $seed = false; if( isset( $_SESSION['seed'] ) ) { $seed = $_SESSION['seed']; ?><p>seed session reused : <?php echo $seed ;?><p><?php } // Set new seed if none exists if ( ! $seed ) { $seed = rand(); $_SESSION['seed'] = $seed; ?><p>seed session created: <?php echo $seed;?><p><?php } // Inject the order into the query $query_args['orderby'] = 'RAND(' . $seed . ')'; } return $query_args; }
-
AuthorPosts