Custom Fields
Support MB Settings Page Custom HTML + PHP callback to display value on Settings Page (MB AIO)

  • Creator
  • #27712
    Resolved Jordan

    Hi! I'm building a settings page where user enters data that is processed somewhere else in a code block. On that page (settings), I'm trying to display field group data using Custom HTML with a PHP callback.
    I've entered the following function in "Code Snippets". What I want is the $index variable to display on the page so the user knows his settings' result in backend. So I'm entering 'mb_quote_index_return' in the "PHP callback" line of the "Custom HTML" field, but nothing shows.
    Can someone tell me where I got it wrong?

    CODE (mb_quote_index_return):

    function get_mb_settings_field( $field_id ) {
        return rwmb_meta( $field_id, ['object_type' => 'setting'], 'options' );
    $quotes = get_mb_settings_field( 'pensees_quotes' );
    $max = count($quotes);
    $lastIndex = get_mb_settings_field( 'start_index' );
    $lastTime = get_mb_settings_field( 'start_date' );
    $lastTimeA = strtotime($lastTime);
    $gap_s = strtotime('now') - $lastTimeA;
    $gap_d = floor($gap_s / (60<em>60</em>24));
    $index = ($lastIndex - 1) + $gap_d;
    $rem = $index;
    while ($rem >= $max) { 
      $rem = $rem - $max;
    $index = $rem;
    echo "Pensée: ".($index + 1)."/".$max;
Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
  • #27713

    I realized my above question isn't well formulated: the code above works well in an Oxygen code block, so this isn't the issue. Now what I want to do is access the same table's data from a Custom Fields Group and display it on a settings page using custom html. For example, here's how I tried to output the value of ' start_index ' through
    1) php callback:
    2) html/php:

    Yet the settings page outputs nothing:

    What I really want to display is the $index variable in the above code. Any help understanding how the custom html works would be greatly appreciated (I did read the documentation but could not figure it out.)


    Long Nguyen

    Hi Jordan,

    Thank you for reaching out.

    The field type custom_html only accepts the callback function name. It also does not support passing the argument on this setting.

    If you use content setting, it only accepts HTML code, not support PHP code. See my screenshot

    Get more details on the documentation


    Thanks! So if I understand, I must wrap everything in a custom function that will echo the settings_field value. Where should I store that custom function so it is accessible via callback? (I use Oxygen which disables function.php).

    Long Nguyen


    You can add the custom function in a custom plugin or use the plugin Code Snippets

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