Working with Multiple Post Types
Explore how to extend search functionality across multiple WordPress post types including posts, pages, courses, and events. Learn to use promise.all to manage multiple REST API requests, combine results for display, and implement error handling to provide seamless user experience in your WordPress theme.
We'll cover the following...
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 ...