Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:23:33+00:00 2026-06-05T13:23:33+00:00

I seem to have a problem with my meta box saving, not totally sure

  • 0

I seem to have a problem with my meta box saving, not totally sure what I’ve done wrong. Any help would be greatly appreciated!

Heres my functions file:

add_action( 'add_meta_boxes', 'cd_meta_box_add' );

function cd_meta_box_add()  
{
    $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
    $template_file = get_post_meta($post_id,'_wp_page_template',TRUE);

    if ($template_file == 'golf.php')
    {
        add_meta_box ( 
            'golf-times', 
            'Golf Opening Times & Prices', 
            'cd_meta_box_cb', 
            'page', 
            'normal', 
            'high' 
        );
    }
}

function cd_meta_box_cb( $post )
{
    $values = get_post_custom( $post->ID );
    $times = isset( $values['golf_meta_box_times'] ) ? esc_attr( $values['golf_meta_box_times'][0] ) : '';
    $prices = isset( $values['golf_meta_box_prices'] ) ? esc_attr( $values['golf_meta_box_prices'][0] ) : '';
    wp_nonce_field( 'golf_meta_box_nonce', 'meta_box_nonce' );
    ?>
    <div style="overflow: hidden;">
        <div style="width: 45%; float: left;">
            <p><label for="golf_meta_box_times">Opening Times</label></p>
            <p><textarea type="text" name="golf_meta_box_times" id="golf_meta_box_times" rows="5" style="width: 90%;" value="<?php echo $times; ?>"> </textarea></p>
        </div>
        <div style="width: 45%; float: left;">
            <p><label for="golf_meta_box_prices">Prices</label></p>
            <p><textarea type="text" name="golf_meta_box_prices" id="golf_meta_box_prices" rows="5" style="width: 90%;" value="<?php echo $prices; ?>"> </textarea></p>
        </div>
    </div>
    <?php   
}


add_action( 'save_post', 'cd_meta_box_save' );
function cd_meta_box_save( $post_id )
{
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

    if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'golf_meta_box_nonce' ) ) return;

    if( !current_user_can( 'edit_post' ) ) return;

    $allowed = array( 
        'a' => array(
            'href' => array()
        )
    );

    if( isset( $_POST['golf_meta_box_times'] ) )
        update_post_meta( $post_id, 'golf_meta_box_times', wp_kses( $_POST['golf_meta_box_times'], $allowed ) );

    if( isset( $_POST['golf_meta_box_prices'] ) )
        update_post_meta( $post_id, 'golf_meta_box_prices', wp_kses( $_POST['golf_meta_box_prices'], $allowed ) );

}
?>

If anyone has a clue how to make this save it would be a great help!

I am also having issues making the data display – but I can only assume thats where it isnt actually saving haha!

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:23:34+00:00Added an answer on June 5, 2026 at 1:23 pm

    functions.php cannot output HTML as far as i know.
    wrap your html in a string and return it, your file might be returning errors.

    Your add_meta_box code seems to be correct, the condition might not be met, are you sure you are sending data over get?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to have a problem with objects' properties' scope. I would like to
I seem to have a problem with getting MVC to fill in my custom
I seem to have a problem understanding how to conditionally test a boolean value
I seem to have a tricky problem since the latest ADT update to release
I have a problem which I cant seem to find answer to through searches
I have a problem which i can't seem to find the solution to. I
I seem to have the exact opposite problem than this question on stopping dock
I have a strange problem that I can't seem to solve. I've quite a
I have a pretty basic problem but I can't seem to figure it out...
I have a very simple C# DataTable problem that I cannot seem to wrap

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.