Select: Choices: Callback: Cache

Support MB Builder Select: Choices: Callback: Cache

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #28446
    Jonathan BaileyJonathan Bailey
    Participant

    IF I have a select box and use a custom callback in "Choices"

    callback: myFunction

    AND myFunction is defined in functions.php as
    function myFunction() {
    return array('red' => 'Red');
    }

    THEN the metabox displays 'Red' in the select box.

    HOWEVER IF I change myFunction to
    function myFunction() {
    return array('blue' => 'Blue');
    }

    THEN the select box still displays 'Red'

    UNTIL I change the "Choices" to
    callback: notMyFunction

    UPDATE AND change it back to
    callback: myFunction

    UPDATE AND THEN the select box displays 'Blue'

    Are we caching somewhere?

    #28456
    Long NguyenLong Nguyen
    Moderator

    Hi Jonathan,

    There is no cache in this case. The new MB Builder saves the field group (meta box) and custom field settings in the database as a post meta. The builder gets the callback function's value for the select field and saves it to the database with the field group. So after you change the return value of the function, you also need to update the field group.

    #28466
    Jonathan BaileyJonathan Bailey
    Participant

    Thank you...

    So is there a way to dynamically populate the select box (say with a list of ids=>post_titles) using the MB Builder?

    #28484
    Long NguyenLong Nguyen
    Moderator

    Hi Jonathan,

    I'm afraid it is not possible with MB Builder. You should use the code to register the field to dynamically get post titles and show them on the select options.
    https://docs.metabox.io/fields/select/

    #32378

    Hi , i was trying to make a function to register metabox via backend, but if i try to return other metabox values for select option field it still does so not return anything , but same function returns hardcoded array to metabox and populates it correctly, so i would assume that action "rwmb_meta_boxes" runs all metaboxes simultaneously, and if to add order/ priority to it would be possible to run metabox for options population and only then the other one which is type "select" ? thanks.

    #32408
    Long NguyenLong Nguyen
    Moderator

    Hi Totis,

    Can you please share the code that creates the fields on your end? The function that returns the option array should be added to the hooked function.

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