• Resolved accounts@push

    (@accountspush)


    ive recently created a themes options page using the settings API and the data is being stored and recalled hoever when i call to the options in my theme e.g <?php echo get_option('rtms_phone') ?> all that it gives me is ‘ARRAY” when the data is outputted in my theme

    when i look in options.php the data field says “serialized data”

    how do i get the data from that field to display as i entered it in my options page.

Viewing 2 replies - 1 through 2 (of 2 total)
  • If you store your options in a single db entry then they are always returned as an array.

    You can access them with:

    $options = get_option( 'rtms_phone' );
    echo $options[ 'some_field_name' ];

    Here, ‘some_field_name’ will be one of your form field values. If you are not sure what’s in there just echo out the array with print_r().

    Thread Starter accounts@push

    (@accountspush)

    still outputs as “ARRAY”

    here is my code for the settings fields si there anything i can add so it shows in the options.php file as individual fields that are not serialized

    <?php // add the admin settings and such
    add_action('admin_init', 'plugin_admin_init');
    function plugin_admin_init(){
    
    	//START OF MAIN SECTION VARIABLES
    register_setting( 'rhythms', 'rtms_business_name');
    register_setting( 'rhythms', 'rtms_email_address');
    register_setting( 'rhythms', 'rtms_phone');//2nd variable to be used in the output function
    
    // define setting section
    add_settings_section(
    'plugin_main',// section slug
    'Main Settings', // section title (displays on actual page)
    'main_section_deatails',//function to describe section
    'plugin');// the page DO NOT CHANGE
    
    //BUSINESS NAME
    add_settings_field(
    'business_text_string',// id of the input element - USE IN FUNCTION
    'Enter the name of your business', // description of the field
    'plugin_setting_string', // name of the function the displays the input field
    'plugin', // the page DO NOT CHANGE
    'plugin_main');// the setting section group
    //BUSINESS E-MAIL
    add_settings_field(
    'email_text_string', // id of the input element - USE IN FUNCTION
    'Enter your email address', // description of the field
    'rtms_email_address_string', // name of the function the displays the input field
    'plugin', // the page DO NOT CHANGE
    'plugin_main');// the setting section group
    //BUSINESS PHONE NO.
    add_settings_field(
    'phone_text_string', // id of the input element - USE IN FUNCTION
    'Phone no.', // description of the field
    'rtms_phone_string',// name of the function the displays the input field
    'plugin',// the page DO NOT CHANGE
    'plugin_main');// the setting section group
    	//END OF MAIN SECTION VARIABLES
    
    	//START OF HEADER SECTION VARIABLES
    	//END OF HEADER SECTION VARIABLES
    
    	//START OF FOOTER SECTION VARIABLES
    	//END OF FOOTER SECTION VARIABLES
    }?>
    
    <?php //MAIN SECTION DESCRIPTION
    function main_section_deatails() {
    echo '<p>Settings for dynamic content throught the theme</p>';
    } ?>
    
    	<!--THE FOLLOWING ARE THE FUNCTIONS WHICH DICTATE THE OUTPUT OF EACH FIELD-->
    
    	<?php //BUSINESS NAME - INPUT FIELD
    	function plugin_setting_string() {
    	$options = get_option('rtms_business_name');
    	echo "<input id='business_text_string'
    				 name='rtms_business_name[text_string]'
    				 size='40'
    				 type='text'
    				 value='{$options['text_string']}' />";
    	} ?>
    
    	<?php //BUSINESS E-MAIL - INPUT FIELD
    	function rtms_email_address_string() {
    	$options = get_option('rtms_email_address');
    	echo "<input id='email_text_string'
    				 name='rtms_email_address[text_string]'
    				 size='40'
    				 type='text'
    				 value='{$options['text_string']}' />";
    	} ?>
    
        <?php //BUSINESS PHONE NO. - INPUT FIELD
    	function rtms_phone_string() {
    	$options = get_option('rtms_phone');// use variable in name='
    	echo "<input id='phone_text_string'
    				 name='rtms_phone[text_string]'
    				 size='40'
    				 type='text'
    				 value='{$options['text_string']}' />";
    	} ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘settings API displaying "ARRAY" instead of actual text’ is closed to new replies.