• luckygolucky

    (@luckygolucky)


    Hello! I need help. I have a custom post type that i have successfully registered and i am able to access through: /wp-json/wp/v2/profile – however I am unable to get ‘search’ paremeter working with the custom fields in that post.

    What that means is that if I do /wp-json/wp/v2/pages?search=somestringhere and say in ‘title’ or ‘content’ or ‘excerpt’ the string ‘somestringhere’ exists, then it returns fine. IF however I do the same for custom type /wp-json/wp/v2/profile?search=somestringhere since I do not have ‘content’ or ‘excerpt’ set then it is only returns results IF ‘title’ is set with ‘somestringhere’ – it is not searching any of the custom fields for that post type.

    Does this make sense? Can anyone help? Thank you.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Yes, I understand. By default WP never searches custom fields, so the same happens with the API. If your site is searching in custom fields, it is due to your theme or a plugin, which failed to extend the same capability to the API. That would be rather odd since API searches still go through WP_Query, so one would expect whatever modifications are added to search in meta data would still apply.

    However, it’s common for code that modifies queries to limit which queries are modified and which are ignored. There is likely something in this criteria that causes the code to ignore API queries. Your best option would be to identify what extension is modifying the searches and get back to the developers regarding how to include the API searches in their extended searches.

    Alternately, write another callback to “pre_get_posts” that modifies API search queries to search meta data as well.

Viewing 1 replies (of 1 total)

The topic ‘REST custom type search not working’ is closed to new replies.