Populate Autocomplete Field with saved data from Database

Support MB Builder Populate Autocomplete Field with saved data from Database

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #41677
    Ahmed E.Ahmed E.
    Participant

    Hi there,

    I'm using an Autocomplete field with AJAX to search for office locations (city).

    1. The API sends the city data as ID and name (e.g. Cairo, Egypt).
    2. We save offices in a separate DB table using rwmb_before_save_post action.

    My question is, how to populate/show saved offices in the WP Editor (e.g. when editing an existing post)?

    Thanks in advance.

    #41678
    Ahmed E.Ahmed E.
    Participant

    #41693
    PeterPeter
    Moderator

    Hello,

    If you use the custom table of Meta Box, the value will display automatically when you edit a post. If you use your custom table, you can try to use the filter rwmb_{$field_id}_field_meta to change the field value before displaying it in the editing form.

    Please read more on the documentation
    https://docs.metabox.io/extensions/mb-custom-table/
    https://docs.metabox.io/filters/rwmb-field-meta/

    #41697
    Ahmed E.Ahmed E.
    Participant

    Hi Peter,
    Thanks for your reply.

    I have tried it but it didn’t work as it accepts an array of values only, so I can’t show the city name but it’s ID only which is not what I’m looking for.

    I have tried a [value => label] array, but both the input label and value were the label and the value was not used at all!

    Is there any other way to do it rather than rwmb_{$field_id}_field_html which I had to use?

    #41729
    PeterPeter
    Moderator

    Hello,

    You can read the list of filters that are supported by Meta Box here https://docs.metabox.io/category/filters/

    But I think the filter rwmb_{$field_id}_field_html is a good way to set the field value by coding before displaying it on the editing page.

    Or you can use the custom table supported by Meta Box to save the field value to a custom table https://docs.metabox.io/extensions/mb-custom-table/

    Otherwise, you should contact an expert developer to help you with your custom table.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.