Support

Account

Home Forums General Issues Extending Search functionality in Relationship field to include post body

Solving

Extending Search functionality in Relationship field to include post body

  • It appears as the Relationship field Search only searches the post title.

    I would like it to also include the body of the post in the search, much like WordPress own post search does (when you add a link through the WYSIWYG).

    Is this possible?

  • Hi @SnitchHomer

    The relationship field uses a WP_Query to find the posts. In the args, the search parameter is set as s. You can read about this here: http://codex.wordpress.org/Class_Reference/WP_Query

    It is possible then to find a plugin or write some custom code that extends the WP search functionality to search also the post_content.

    Thanks
    E

  • Hi @elliot,

    I think the default WP_Query behaviour is to search both post_title and post_content, so I am surprised this is not working in the Relationship field.

    Assuming this was a choice made by you, is there any suitable hook in ACF to override this? (Such as a filter in Relationship field.)

    Or do you think there is a WP core hook?

  • Hi, Elliot.

    I have WP Custom Fields Search plugin installed – it is an exellent solution to search content from the front-end not only in Post Title or Post content, but all other custom fields.

    Unfortunately in back-end AJAX search for Relationship field is searching only Post Title, not even Post Content, as SnitchHomer said.

    Is it possible to do some customization to make search possible not only by Title, but by Body and all (or some) text custom fields?

    For example we have such structure:

    1. Movie post type
    2. Actor post type

    In Movie custom fields I have Actors realtionship field, that helps me to choose actors, that cast in the movie.

    Each Actor have additional Custom Fields, like Original name, Nickname and other Text Fileds, that helps me to quckly search actors database.

    It will be great if I can search Actors not only by their Name, but also any of Custom Fields.

    I would be grateful for any help.

  • Hi guys.

    As I have written above, ACF uses a WP_Query with a s argument to search. WP should natively search post_content in a new WP versions, but you can always hook in and modify the WP_Query args like so:

    http://www.advancedcustomfields.com/resources/filters/acf-fields-relationship-query/

    Thanks
    E

  • Hi @elliot,

    I guess the question then is why our installs are only searching in the post_title. Both me and Fade seem to have this problem. Any ideas?

  • Hi @SnitchHomer

    I can’t explain why, but my first thought is that you have a plugin, or theme code which is modifying the way that WP searches data.

    Perhaps, the issue is due to an older version of WP? I’m not sure which version the better search was added, but it is one of the most recent versions.

    Thanks
    E

  • Hi @SnitchHomer

    Perhaps the best move from here is to setup a brand new install of WP on a local host and test our ACF relationship field. Then add in each plugin one by one, and finally the theme code.

    This should reveal which is causing the issue.

    Thanks
    E

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Extending Search functionality in Relationship field to include post body’ is closed to new replies.