I am cutomizing my archive layout for search results. The template has a parent layout. Inside there I want to display an information like: Your search term "documentation" was found on 16 posts. (I am using Relevanssi)
I am using [wpv-search-term] to display the search term. But how to display the total amount of the listet posts in search results? Is that possible?
I am looking forward to your anwer!
Hi Frank,
Thank you for contacting us and I'll be happy to assist.
To show the total number of posts/search results, found by the View, you can use "[wpv-found-count]" shortcode:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-found-count
Note: remember to include it before the loop's start ( i.e. before <!-- wpv-loop-start --> tag ), in the "Loop Editor".
Please let me know if this helps.
regards,
Waqar
Dear Waqar,
Thank you for your fast reply. I can solve my problem with your solution.
One more question to the same topic: Is there a way to display the result in the parent layout of my search result template? (screenshot)
Hi Frank,
Thanks for writing back.
The shortcode [wpv-found-count] can be used within the "View" where the actual query has been processed, but not before that. This screenshot will further clear this up:
hidden link
In case, you'd like to show its value inside the layout, but outside the relevant view, a workaround is to use some JS script, to move it from one place to another.
For example, you can your shortcode inside the view, where it can be used inside a special span tag:
<span id="original-location">[wpv-found-count]</span>
Next, you'll add an empty span tag, in the layout where you'd actually like to show that value:
<span id="moved-location"></span>
In your View's "CSS editor", you can add following code to hide both these span tags, when the page loads:
span#original-location,
span#moved-location {
display: none;
}
The actual script to move the value from the original location to the desired location can be added into the View's "JS editor":
$( document ).ready(function() {
$("span#original-location").contents().appendTo("span#moved-location");
$("span#moved-location").show();
});
For a more personalized and detailed assistance around custom code, you can consult, one of our certified consultants:
https://toolset.com/contractors/
Thank you for your fast and detailed answer and solution! Perfect.
Toolset support rocks 🙂