One Filter for Two Elementor Widgets

Home Forums Product Support Forums Ajax Search Pro for WordPress Support One Filter for Two Elementor Widgets

This topic contains 9 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 6 months, 1 week ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #46328
    ari
    ari
    Participant

    Hello!
    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!

    #46332
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #46333
    ari
    ari
    Participant

    Is 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

    • This reply was modified 6 months, 2 weeks ago by ari .
    • This reply was modified 6 months, 2 weeks ago by ari .
    #46338
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #46344
    ari
    ari
    Participant

    Hi!

    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?

    #46350
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    You 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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #46355
    ari
    ari
    Participant

    That 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

    #46359
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    I 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';
      });
    });
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #46362
    ari
    ari
    Participant

    Unfortunately 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

    • This reply was modified 6 months, 1 week ago by ari .
    #46369
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    I’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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.