Custom Fields
Re-Envisioned
Support Meta Box Builder Select: Choices: Callback: Cache

  • Creator
    Topic
  • #28446
    Jonathan 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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #28456
    Long Nguyen
    Moderator

    Hi Jonathan,

    There is no cache in this case. The new Meta Box 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 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 Meta Box Builder?

    #28484
    Long 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/

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