Working with Multiple Post Types
Learn to modify the fetch request to get results of multiple post types.
We'll cover the following...
At the moment our search only works with the event post type because in the fetch
method, we have hard coded the URL to be /wp-json/wp/v2/event?search=
.
sendSearchRequest(){fetch(siteData.root_url+ '/wp-json/wp/v2/event?search='+this.searchInput.value).then((response)=>{}).then((data)=>{});
Search URL hardcoded for event posts
We want posts, pages, courses, and teachers to be included in the search. To look for pages we need to append /wp-json/wp/v2/pages
at the end of the root URL. If we use this URL in the fetch
method, we will be able to search for the About Us or Contact Us ...