Hi,
I have 2 post types – COURSE and MODULES. Every course will have many modules.
I have added Post Relationshop type with the name ‘course_module_relationship’ in COURSE post type and assigned MODULES to it.
Now I have a front-end ajax search form with a textbox and other filters. If I search any keyword with textbox, I want to search in the COURSE post type title or associated MODULE titles.
For example,
I have 3 courses with modules:
1/ Learn Computer
— Basic computer
— Advance computer
2/ Learn English
— Learn Grammer
— Learn Pronounciation
3/ Learn Maths
— Learn Addition
— Maths with Computer
So if one searches for the word “Computer” they should see the Course #1 and #3.
I followed this article – https://wpza.net/how-to-search-post-title-and-meta-value-in-wordpress/ and managed to search the keyword in the COURSE title. But I am not able to understand how can I make it search in the MODULE titles, as I found that relationship field saves it’s data as a serialized array.
So is it possible?
You cannot search the text in COURSES and have it also search MODULES. In order to find the title of MODULE when searching COURSE the content for MODULE that you want to be able to search must be part of the COURSE post in either the title, content of a custom field if you are searching custom fields.
What this means is that when you update a course post you must create an acf/save_post hook that gets all of the related modules and saves the titles of these modules into some other custom field related to course then you search this custom field.