Select Advanced: Populate Options from Custom Model based on another field value

Support MB Custom Table Select Advanced: Populate Options from Custom Model based on another field value

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

    Hi there,

    I have three entities: Provider (CPT), Service (Custom Model), Plan (Custom Model)

    Each Provider has multiple services, and each service has multiple plans.

    I an using a Select Advanced field for service & plan.

    My question is, when editing an existing record, how to populate provider plans as options in the plan select advanced field so that the current selected plan appears in the options as well as other plans of the same service?

    Thanks in advance.

    #42181
    PeterPeter
    Moderator

    Hello,

    If you use the custom model, it does not work with MB Relationships or post field. So you will need to create a custom callback function for the select_advanced field to display a list of models and it is beyond our scope of support.
    If you are not able to do that, please contact us here https://metabox.io/contact/
    and submit a customization service request, our development team will help you with an extra fee.

    #42183
    Ahmed E.Ahmed E.
    Participant

    Hi Peter,

    Thanks for your reply.

    I know Custom Models are not yet supported by relationships extension and I am not looking for a customization service.

    My questions are:
    What is the filter/action for setting the field options?
    How to get box fields’ values inside the callback function?

    #42196
    PeterPeter
    Moderator

    Hello,

    >> How to get box fields’ values inside the callback function?
    To get a normal field value inside the callback function, you can use the function get_post_meta(). To get a field value of a model, you need to use an SQL query.

    >> What is the filter/action for setting the field options?
    I do not understand this question. If you want to customize the options for a field, you can use the filter hook rwmb_normalize_{$field_id}_field. Refer to the documentation https://docs.metabox.io/filters/rwmb-normalize-field/

    #42206
    Ahmed E.Ahmed E.
    Participant

    Hi Peter,

    I can easily build the callback function, the only problem is how to get the object ID inside the callback function in order to be able to populate the options?

    #42225
    PeterPeter
    Moderator

    Hello,

    You can try to use this code to get the post ID in the admin area

    $post_id = null;
    if ( isset( $_GET['post'] ) ) {
        $post_id = intval( $_GET['post'] );
    } elseif ( isset( $_POST['post_ID'] ) ) {
        $post_id = intval( $_POST['post_ID'] );
    }
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.