Hi there,
The custom search I've implemented on some page of my site, isn't working the way it's supposed to. When I get on the page, the initial output of the custom search is clickable. But, when I applied a filter, the links aren't clickable. For example on this page: hidden link.
Can you tell me what's going wrong here?
Thanks!
Greetings,
Kerim
Hi Kerim,
Thank you for contacting us and I'd be happy to assist.
I noticed your view includes the following custom script to make the page redirect to a specific URL from the result, when clicked.
jQuery( document ).ready( function( $ ) {
$(".postborder").click(function() {
window.location = $(this).attr("data-url");
return false;
});
});
This script executes when the page loading completes, but the view is set to update results through AJAX, which doesn't reloads the page.
To fix this, you can update your custom script, so that it is wrapped in a named function, for example:
jQuery( document ).ready( function( $ ) {
viewClickFunction();
});
function viewClickFunction() {
$(".postborder").click(function() {
window.location = $(this).attr("data-url");
return false;
});
}
After that, you can include the name of this function "viewClickFunction" in the "will run after updating the results" field, in "Custom Search Settings" section.
( Screenshot: hidden link )
As a result, this script will execute on page reload as well as when the view's results will update through AJAX.
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Thanks for the explanation. I did what you said (in the view: "psycholoog-mindmonks"), but I'm still experiencing the same problem.
I've checked the page and noticed that the result cards are clickable after the search filter is changed.
Screencast: hidden link
Can you please check the page again?
Aah I see what's happening! When I go to the page and click on certain filter, it works fine. However, when I click on the pagination button to show me the other search results, it stops working. Can you tell me how to fix this?
To execute your custom function, whenever the results update through the AJAX pagination, you can additionally hook it with "js_event_wpv_pagination_completed" event.
Example:
jQuery( document ).on( 'js_event_wpv_pagination_completed', function( event, data ) {
viewClickFunction();
});
The above code block can be included below the already added custom script blocks and it should work.
My issue is resolved now. Thanks a bunch :D!!!!