Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › ASP and the relationship field of ACF
This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko 5 years, 7 months ago.
- AuthorPosts
- September 14, 2018 at 5:26 pm #19196
Hello,
I’m wondering if there is a way to automatically search into a relationship field of avanced custom field (i’m using the pro version). I’m making a website with already more than 700 books (the data came from the database of the old site) and every book got one relationship field (depending on the number of authors). There are too much books to manually add the name of the author(s) in the additional search tag field for each book, is there a way to “read” the array of the relationship field for each books and display the books that are linked to an author when we search for his name ? Or autopopulate the additional search tag with the result of the relationship field ?
I’ve seen in the forum that you gave a code to someone to make a field from acf display well in the search result, my problem is close but not exaclty the same : i don’t need to the relationship result to be display in the results, just to be linked to the post.
Thanks
RegardsSeptember 15, 2018 at 11:57 am #19203Hi!
Well, it might be possible to get the related post objects and index them. For this to work, you will need to use the index table engine:
– Index table introduction
– Index table configuration + generation
– Enabling the index
..and a custom code.I have put together a small code snippet, but I did not test it yet, so please be careful. Add this to the functions.php in your theme/child theme directory (copy from line 3 only!). Before editing, please make sure to have a full site back-up just in case!
Change the following variables as you need them:
– $field_name -> The relationship field name
– $index_title -> true or false, if you want to index the related post title
– $index_content -> true or false, if you want to index the related post contentOnce you have the code setup, you need to re-create the index table, and that should hopefully do it.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
September 16, 2018 at 12:44 pm #19214Hello,
Thanks for this code, it works well but it doesn’t achieve what i’m try to do.
If I understand your code right, it fetch every item with a certain relationship field and index his title or content so it can be return in the search.
But i’m already indexing the custom posts “authors” (which are linked with a relationship to the custom post “books” ) in the index table so this code index items that are already in the table.
The search work already well when i search a book or an author because i’m indexing those two custom posts.
Actually only the books with the name of the author in the description of the book are returned, it want all the books from the same author to be in the search results (without the need of putting the name of the author in a “additional search tag” for each book).
What I need is that when i search for the name of an author the search “read” the relationship field that link this author to books and return all the books linked to this author.
Do you think this kind of thing can be done ?September 17, 2018 at 8:23 am #19219Hi,
The code actually indexes the items within the relationship fields as part of the current post. They are indexed separately as well, but this makes sure, that the posts within the relationship fields are also indexed as part of the original post.
I guess, what you are trying to achieve might not be possible without major customization to the core plugin code, unfortunately.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
The topic ‘ASP and the relationship field of ACF’ is closed to new replies.