I’m trying to get Relevanssi to query the relationship custom field I have set up but it doesn’t seem to read the values. I’ve added the name to the custom fields to index box but it doesn’t seem to help. Can anyone advise on what I need to do to fix this?
The relationship field saves it’s data as a serialized array of post ID’s.
Can you elaborate more on your code / relevanssi relationship query?
Thanks for your response! Basically the site deals with books. Previously authors were a separate post type and were attached to books via a relationship picker. Something went wrong with the permalinks which I’ve been unable to fix which means that I’ve now moved the author information onto the books pages. However, the information about the author(s) (e.g.: bio) is still saved as a separate post type.
The issue is that you can’t search by author name and bring up the relevant books, I presume because, unlike other text fields for example, the relationship picker present different information.
Do you know of a way to force Relevanssi (which I’m using in order to factor in various ACF custom fields) to search the post titles (in this case author names) selected in the relationship field rather than the numerical IDs assigned?
Thanks very much!
This is a great question, and one which i’m sure is possible, but one that I have no idea how.
My first though is one which has 2 parts:
1. Filter query
If you searched for ‘Elliot Condon’, find the post with this title (the bio post). Now you have an id of 123. Use this ID to modify the search parameter so that your search is for 123 (maybe you can target this as a meta_query only?).
This should hopefully find books that have an author of 123.
2. Filter the results
If the above query works, then you can swap out ‘123’ for ‘Elliot Condon’ and your results should read correctly.
This will be pretty complex and will require a lot of debugging and searching through source code, but it’s worth a shot.
Also, I would ask the guys over at Relevanssi what their thoughts are.