Hi Waqar,
Have another problem I need each result to be unique and not repeat in results list, how do I change the search to achieve this?
Thanks
Hi,
The duplicate results are showing because, the view is for the child post type, whereas the post link in the results is shown for the posts from the parent post type.
To overcome this you can follow these steps:
1. In your view's output, you'll include a class "result-items" to the ul tag that wraps the results:
<ul style="width:20vw; height:30vh; overflow:auto; padding:5px; list-style-type: none; margin-left: 20vw" class="result-items">
2. Also, to make them identifiable, you'll include a special class with the post ID, to the li tag that wraps the post link :
<li class="result-item-[wpv-post-id item='@plant-complaint.parent']"> [wpv-post-link item="@plant-complaint.parent"] </li>
3. The following script will be needed in the view's "JS editor" which can hide all the results items where the parent post ID is the same, except for the first instance:
jQuery(document).ready(function(){
jQuery('ul.result-items li').each(function() {
var classNames = jQuery(this).attr("class");
jQuery('li.'+classNames).not(':first').hide();
});
});
I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar
My issue is resolved now. Thank you!