Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › One Filter for Two Elementor Widgets
- This topic has 9 replies, 2 voices, and was last updated 2 years, 5 months ago by
Ernest Marcinko.
-
AuthorPosts
-
December 8, 2023 at 2:21 pm #46328
ari
ParticipantHello!
I’ve wanted to add ‘pinned’ posts that would always stay on top, so I’ve created two Elementor Posts Widgets on the same page. One only includes posts with the term “Featured” while others exclude them. This works great since I can also use different loop templates for them.
However the filter will only work on one widget at a time, currently the one on top.How do I make it so the same filter will apply to both widgets at the same time?
Thank you!
December 8, 2023 at 5:37 pm #46332Ernest Marcinko
KeymasterHi,
I’m afraid this is not possible to do. For each search query there is only a single way to override, hook into and change the results.
Even if it was doable, the only thing that would happen is you would see the same exact results on both widgets (correctly), which is probably not what you are looking for.
December 9, 2023 at 1:49 am #46333ari
ParticipantIs there some way to change the order to create featured posts that are always on top? I’m using a custom post type so I can’t make them sticky. I’ve also tried using Seamless Sticky Custom Post Types but it doesn’t seem to work
December 11, 2023 at 10:04 am #46338Ernest Marcinko
KeymasterHi,
When searching the stickied items will not actually stick unfortunately. You can however use the results priorities for that. So in case of a match the selected items will be pushed to the top of the results list.
December 11, 2023 at 5:13 pm #46344ari
ParticipantHi!
Thank you! That seems to work, however only after I search something. Is there a way to keep them on top before searrching as well or, if that’s not possible, can I add another widget with the featured ones on top and hide it if there is a search?
December 12, 2023 at 3:49 pm #46350Ernest Marcinko
KeymasterYou are welcome!
You could in theory try the auto-populate feature. Set it up like this. That will basically trigger an empty search which should yield the results with the prioritized items on top.
December 12, 2023 at 9:44 pm #46355ari
ParticipantThat doesn’t work, because when there’s no filters the itens aren’t on top. I currently added the featured ones as a separate element and hide it based on the search query. However I don’t know how to access the query on javascript, so I had to enable “Update the browser address bar with the last selected options?” and use the current url as a parameter. Is there a way to access the query information without updating the browser url?
Thank you for all the help so far
December 13, 2023 at 9:58 am #46359Ernest Marcinko
KeymasterI think you could hook into the asp_search_start event, which is fired when a search is triggered via ajax search pro.
Something like:
document.querySelectorAll(".asp_main_container").forEach(function(el){ el.addEventListener("asp_search_start", function(event) { document.querySelector("#featured_element").style.display = 'none'; }); });December 13, 2023 at 1:38 pm #46362ari
ParticipantUnfortunately that doesn’t work either. The same issue happens: when there are no active search filters (ie filters_initial=0) the featured posts won’t go on top. 🙁 If there’s no way to get the query parameters through js I might just leave it with the url changed, then.
Thank you again
December 15, 2023 at 12:50 pm #46369Ernest Marcinko
KeymasterI’m not sure if there is a way then I’m afraid 🙁
You could still try to experiment with 2 widgets and use the custom code above to try to hide the first widget when the search is starting out. Other than that I don’t think there is a different solution.
-
AuthorPosts
- You must be logged in to reply to this topic.