I am trying to: I want to be able to search the text on the page and for it to say "Yes, we have been there." or if it doesn't fin the text on the page, it says, "We have not been there."
Link to a page where the issue can be seen: hidden link
I expected to see:
Instead, I got:
Hi, can you tell me how each location is stored on your site? Is each location a custom post, or a custom field associated with a post, or are the locations simply part of a single post's main content, or is there some other way you have set up this list of locations?
Views has a text search filter that will help you search for text in a post's title or a post's body text. If you need to include taxonomy terms and custom field values in that search, you need to use a plugin like Relevanssi to extend the text search functionality. More information about that here:
https://toolset.com/documentation/user-guides/searching-texts-custom-fields-views-relevanssi/
If the search text is found in any post, then you can show the "We've been there" message. If not, you can show the "We have not been there" message. You can do this in the Loop Output of a View of posts. Just leave the wpv-loop tags empty, and place your message outside the loop and in the "no results found" area like this:
[wpv-layout-start]
[wpv-items-found]
We've been there.
<!-- wpv-loop-start -->
<wpv-loop>
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
We haven't been there.
[/wpv-no-items-found]
[wpv-layout-end]
Let me know how these locations are set up on your site and I can offer some more advice.
Hi, thanks for the reply.
I did not use types or any custom post types to make that page.
It was made with Divi's toggle module.
They are just plain text inside the toggle on the page.
So then I should use the Relevanssi plugin to help achieve this effect?
Thanks.
If the toggle modules were added to a page or post using the Divi builder, then Relevanssi will not be necessary. I just ran a quick test and I was able to get search working without it. I created a View of Pages (since I added the toggle modules to a page), and added a Query Filter to filter by post ID. I inserted the Page's ID there, so the View only searches through the content of this one Page.
Then I went to the Filter Editor panel. If you cannot see the Filter Editor panel, activate it in the Screen Options tab at the top of the View editor admin page. Here I added a Text Search and a Submit button. Next I placed the code from above in the Loop Output editor.
Then in the Page editor, I inserted this View into a Text module using the Fields and Views button. Now when I enter text into the search box and click Submit, I see the results filtered as expected. One minor thing here is that the text "We've been there" shows in the results even before text is entered in the search box. If that's a problem for you, we can work on modifying that once you have the View working up to this point.
Let me know if you are able to get this working, or if you get stuck somewhere.
Nice! Thanks.
Got it to work.
Yes, the text "We've been there" shows in the results even before text is entered in the search box.
How would I make that hidden until they hit the submit button?
Okay great. Make a small adjustment in the Loop Output editor that wraps the message in a span tag, then add some JS to hide this span on initial page load. Loop editor:
<span class="js-hide-on-load">We've been there.</span>
JS panel:
jQuery(document).ready(function(){
jQuery('.js-hide-on-load').hide();
});
Awesome. Thanks!
One last question.
Is there any way to set an anchor? Like if they type in the word that is on the page, it then jumps to it and open the toggle so the person can see it.
Thanks!
Matt
I don't know if Divi offers the ability to programmatically open a toggle module with JavaScript. The documentation here does not mention it:
hidden link
Are you able to provide a link to any documentation showing how to do this part? It's not really Toolset-related so I'm not able to research this for you.
Ok Thanks for all your help.