Home Forums Pre-purchase Questions External search


External search

  • Hello,

    I’d like to know if in the Extended version it’s possible to create a field that searches a term in an external database and displays a few suggestions while the post author is typing it. Sorta like the search box for categories does while you’re writing a new post, but in my case the search should be done on an external source. Then the post author would choose one option from the list returned by that search and the field would point to an external page.

    I need this because the data in this field will come from a big database that isn’t connected to WordPress and it’s unfeasible to create new categories for each page it points to, as the database is constantly updated.

  • +1 I have the same question.
    I need a field that query an external API with after the user has enter a minimal search (3 letters for example), send the query each time the search change and return a list of options that the user can select : key as object_id and name as label.

    Thank you

  • I cannot give you any code except for a few snippets, but it is possible.

    First you create select field with the following options

    Choices = dynamically generated
    Stylized UI = Yes
    Use AJAX to lazy load choices = Yes

    Create an acf/prepre_field filter to dynamically generate the choices. The reason why we do this on acf/prepare_field is so that the choices are only loaded when used. Connect to your external DB and populate the choices from there.

    Create an acf/load_field filter for the same field. This filter should only run during AJAX requests. At the top of the function add:

    if (!defined('DOING_AJAX') || !DOING_AJAX) {
      return $field;

    Other than this it does the same thing that the first function does and you can just call that function and return what it returns.

    And then create and acf/format_value filter that will use the selected value to get what you need from the external DB and format it in whatever way it needs to be formatted.

    There may be other ways to do this, but I had to do something similar. The main difference was I was not connecting to an external DB.

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

You must be logged in to reply to this topic.