0

I am having trouble calling a field and displaying its content at the frontend from a custom theme option page. This is the code I am using to display my custom theme option at the backend

  add_action( 'admin_init', 'theme_options_init' );
  add_action( 'admin_menu', 'theme_options_add_page' );

 /** Init plugin options to white list our options **/
  function theme_options_init(){
        register_setting( 'options', 'website_options', 'theme_options_validate' );
  }
 /** Load up the menu page **/
  function theme_options_add_page() {
        add_theme_page( __( 'Blurb Options', 'websiteBlurbs' ), __( 'Blurb Options',      'websiteBlurbs' ), 'edit_theme_options', 'theme_options', 'theme_options_do_page' );
 }

 /** Create the options page **/
  function theme_options_do_page() {
            if ( ! isset( $_REQUEST['settings-updated'] ) )
            $_REQUEST['settings-updated'] = false;
 ?>
  <div class="wrap">
  <?php screen_icon(); echo "<h2>" . get_current_theme() . __( ' Page Settings', 'websiteBlurbs' ) . "</h2>"; ?>
  <?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
  <div class="updated fade"><p><strong><?php _e( 'Options saved', 'websiteBlurbs' ); ?></strong></p></div>
  <?php endif; ?>
  <form method="post" action="options.php">
        <?php settings_fields( 'options' ); ?>
        <?php $options = get_option( 'website_options' ); ?>
        <table class="form-table">
            <td><h2>About Page</h2></td>
            <?php /* ABOUT */ ?>
            <tr valign="top"><th scope="row"><?php _e( 'Title Blurb', 'aboutBlurb' ); ?></th>
        <td>
                    <input id="website_options[about]" class="regular-text" type="text" name="website_options[about]" value="<?php esc_attr_e( $options['about'] ); ?>" style="width:50%; padding:1em;" />
                    <label class="description" for="website_options[about]"></label>
                </td>
            </tr>
            <td><h2>Our Team</h2></td>
            <?php /* PROPERTY */ ?>
            <tr valign="top"><th scope="row"><?php _e( 'Title Blurb', 'teamBlurb' ); ?></th>
                <td>
                    <input id="website_options[team]" class="regular-text" type="text" name="website_options[team]" value="<?php esc_attr_e( $options['team'] ); ?>" style="width:50%; padding:1em;" />
                    <label class="description" for="website_options[team]"></label>
                </td>
            </tr>
            <td><h2>Property Page</h2></td>
            <?php /* PROPERTY */ ?>
            <tr valign="top"><th scope="row"><?php _e( 'Title Blurb', 'propertyBlurb' ); ?></th>
                <td>
                    <input id="website_options[property]" class="regular-text" type="text" name="website_options[property]" value="<?php esc_attr_e( $options['property'] ); ?>" style="width:50%; padding:1em;" />
                    <label class="description" for="website_options[property]"></label>
                </td>
            </tr>
        </table>
        <p class="submit">
            <input type="submit" class="button-primary" value="<?php _e( 'Save Options', 'websiteBlurbs' ); ?>" />
        </p>
  </form>
  </div>
  <?php
 }

 /** Sanitize and validate input. Accepts an array, return a sanitized array. **/
  function theme_options_validate( $input ) {
 // Say our text option must be safe text with no HTML tags
        $input['about'] = wp_filter_nohtml_kses( $input['about'] );
        $input['property'] = wp_filter_nohtml_kses( $input['property'] );
        $input['team'] = wp_filter_nohtml_kses( $input['team'] );
        return $input;
 }

I know how to call a field from a custom post type by using echo get_post_meta($post->ID, 'customfieldname', true); but when I try using this to call field aboutBlurb i am unable to generate the content from the field to display at the frontend. I am not receiving any errors or a reasons why I can not display it.

What am I missing to make this work correctly?

2 Answers 2

0

I'm not sure how you've decided to save your options but if I were to guess based on the code above, you're saving your 'aboutBlurb' as an index in the website_options array which I also assume you're saving in the actual WordPress Options - website_options[about].

To get that data maybe try this:

$website_options = get_option('website_options');
echo $website_options['about'];
0
0

Try this way, may help you. I fetch the a page 's thread then fetch associated custom field by putting its name.

     $homeInsurance= new WP_Query( 'post_type=page&page_id=7' );    
        while ($homeInsurance->have_posts()) : $homeInsurance->the_post();

        $thisPageID         = get_the_id(); 
        $home_insurance_urdu_translation_image_path = get_post_meta($thisPageID, 'home_insurance_urdu_translation_image_path', true);


        endwhile;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.