Getting value from Settings page

Support MB Settings Page Getting value from Settings page

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #48332
    jeff@developedbydesign.com[email protected]
    Participant

    I have a settings page (option name: website-info) that has a radio set (enable_site_commenting) with selections for "Disabled" and "Enabled."

    I'm trying to check the enable_site_commenting selection and only run the following code if "Enabled" is selected. Then, at the end of the code snippet, set enable_site_commenting back to "Disabled".

    I've been trying to use varitions of this, but my site keeps crashing:

    $site_commenting_value = rwmb_meta( $enable_site_commenting, ['object_type' => 'setting'], $website-info );
    
    if $site_commenting_value = 'Enabled' {
        RUN_THIS_CODE
    }
    #48336
    PeterPeter
    Moderator

    Hello Jeff,

    Thanks for reaching out.

    I see that there are some issues in your code and they are not related to the way to get the field value on a settings page.

    1. If enable_site_commenting is the field ID and website-info is the option name (not the settings page ID), you need to remove the $ character.

    2. No brackets in the if statement.

    3. Use an assignment variable instead of comparison operator

    $site_commenting_value = rwmb_meta( 'enable_site_commenting', ['object_type' => 'setting'], 'website-info' );
    
    if ( $site_commenting_value == 'Enabled' ) {
        RUN_THIS_CODE
    }

    If you are not able to complete the task, we offer a customization service with an extra fee. Please contact us here for more details https://metabox.io/contact/

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