Custom Fields
Re-Envisioned
Support General Generating PHP and Displaying Settings on Frontend

  • Creator
    Topic
  • #33122
    Resolved Jack_B
    Participant

    Hi,

    I just purchased the plugin and was wondering if it's possible to generate the PHP required for displaying fields on the front end.

    I'm coming from ACF where you could use an extension to write this for you (https://hookturn.io/downloads/acf-theme-code-pro/?utm_source=awesomeacflink). Is there something equivalent for Metabox?

    I can see you can generate it with Views, which I thought was the same - although it uses Twig (I think), so i can't use that code directly in templates.

    If it's not possible, could I please have some assistance with displaying a settings field in my templates. I have created a settings page. This is what's generated in Views:

    {% set group = attribute( site, 'global-settings' ) %}
    {{ group.opening_hours }}

    How can I translate that to the plain php equivalent?

    $value = rwmb_meta( $field_id, ['object_type' => 'setting'], $option_name );
    echo $value;

    I'm not sure how to declare the option name.

    Thanks in advance

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

    Hi,

    it's possible to generate the PHP required for displaying fields on the front end.

    Meta Box does not support a feature to generate code to output the field value like that.

    If you want to get the field value of the settings page, please clarify the field ID and option name. For example:

    $value = rwmb_meta( 'text_id', ['object_type' => 'setting'], 'my_option' );
    echo $value;

    Get more details on the documentation
    https://docs.metabox.io/displaying-fields/#using-code
    https://docs.metabox.io/extensions/mb-settings-page/

    #33151
    Jack_B
    Participant

    Thank you, I was able to get the snippet you posted to work

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