Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Junior Member bizkital's Avatar
    Join Date
    Mar 2013
    Posts
    2
    Member #
    35871
    Hi,

    I've setup some meta boxes on the post editor admin page in a wordpress project, the box and custom fields render to the page fine but it's not saving the content that's in the fields when I click the publish button, I'm sure I had it working at one point but I must have changed something and forgot.

    I anyone can point me to what's wrong here I would be most grateful.

    Here's the code.

    PHP Code:
    <?php
    /* Fire our meta box setup function on the post editor screen. */
    add_action'load-post.php''post_meta_boxes_setup' );
    add_action'load-post-new.php''post_meta_boxes_setup' );

    /* Meta box setup function. */
    function post_meta_boxes_setup() {

        
    /* Add meta boxes on the 'add_meta_boxes' hook. */
        
    add_action('add_meta_boxes''extra_content_meta_box_add');

        
    /* Save post meta on the 'save_post' hook. */
        
    add_action('save_post''extra_content_meta_box_save');
    }

    /* Create one or more meta boxes to be displayed on the post editor screen. */
    function extra_content_meta_box_add() {
        global 
    $post;
        
    /* Add meta boxes depending on page template */
        
    if ('homepage.php' == get_post_meta($post->ID'_wp_page_template'true)) {
            
    add_meta_box(
                
    'extra-content-meta-boxes',        // Unique ID
                
    'Extra Content Boxes',            // Title
                
    'render_meta_boxes',            // Callback function
                
    'page',                            // Admin page (or post type)
                
    'normal',                        // Context
                
    'high'                            // Priority
            
    );
        }
    }

    /* Display the post meta box. */
    function render_meta_boxes() {

        
    wp_nonce_field(basename(__FILE__), 'extra_content_meta_box_nonce');

        global 
    $post;
        
    /* Escape if we're doing an auto save */
        
    if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
            return 
    $post_id;

        
    $custom get_post_custom($post->ID);
        
    $sb1_title $custom['slider_box1_title'][0];
        
    $sb1_text $custom['slider_box1_text'][0];
        
    $sb2_title $custom['slider_box2_title'][0];
        
    $sb2_text $custom['slider_box2_text'][0];
        
    $sb3_title $custom['slider_box3_title'][0];
        
    $sb3_text $custom['slider_box3_text'][0];
        
    $sb4_title $custom['slider_box4_title'][0];
        
    $sb4_text $custom['slider_box4_text'][0];
        
    $cb1_title $custom['content_box1_title'][0];
        
    $cb1_text $custom['content_box1_text'][0];
        
    $cb2_title $custom['content_box2_title'][0];
        
    $cb2_text $custom['content_box2_text'][0];

        
    ?>
        <style type="text/css">
            <?php include('css\extra-content-meta-boxes.css'); ?>
        </style>
        <div class="meta-fields">
            <fieldset>
                <legend>Slider box #1</legend>
                <div>
                    <label for="slider_box1_title">Title:</label>
                    <input type="text" name="slider_box1_title" value="<?php echo $sb1_title?>" />
                </div>
                <div>
                    <label for="slider_box1_text">Text:</label>
                    <textarea name="slider_box1_text" rows="4">
                        <?php echo $sb1_text?>
                    </textarea>
                </div>
            </fieldset>
            <fieldset>
                <legend>Slider box #2</legend>
                <div>
                    <label for="slider_box2_title">Title:</label>
                    <input type="text" name="slider_box2_title" value="<?php echo $sb2_title?>" />
                </div>
                <div>
                    <label for="slider_box2_text">Text:</label>
                    <textarea name="slider_box2_text" rows="4">
                        <?php echo $sb2_text?>
                    </textarea>
                </div>
            </fieldset>
            <fieldset>
                <legend>Slider box #3</legend>
                <div>
                    <label for="slider_box3_title">Title:</label>
                    <input type="text" name="slider_box3_title" value="<?php echo $sb3_title?>" />
                </div>
                <div>
                    <label for="slider_box3_text">Text:</label>
                    <textarea name="slider_box3_text" rows="4">
                        <?php echo $sb3_text?>
                    </textarea>
                </div>
            </fieldset>
            <fieldset>
                <legend>Slider box #4</legend>
                <div>
                    <label for="slider_box4_title">Title:</label>
                    <input type="text" name="slider_box4_title" value="<?php echo $sb4_title?>" />
                </div>
                <div>
                    <label for="slider_box4_text">Text:</label>
                    <textarea name="slider_box4_text" rows="4">
                        <?php echo $sb4_text?>
                    </textarea>
                </div>
            </fieldset>
        </div>
        <div class="meta-fields">
            <fieldset>
                <legend>Content box #1</legend>
                <div>
                    <label for="content_box1_title">Title:</label>
                    <input type="text" name="content_box1_title" value="<?php echo $cb1_title?>" />
                </div>
                <div>
                    <label for="content_box1_text">Text:</label>
                    <textarea name="content_box1_text" rows="4">
                        <?php echo $cb1_text?>
                    </textarea>
                </div>
            </fieldset>
            <fieldset>
                <legend>Content box #2</legend>
                <div>
                    <label for="content_box2_title">Title:</label>
                    <input type="text" name="content_box2_title" value="<?php echo $cb2_title?>" />
                </div>
                <div>
                    <label for="content_box2_text">Text:</label>
                    <textarea name="content_box2_text" rows="4">
                        <?php echo $cb2_text?>
                    </textarea>
                </div>
            </fieldset>
        </div>
        <div class="clear"></div>
        <?php
    }

    function 
    extra_content_meta_box_save() {
        global 
    $post;

        
    /* Escape if we're doing an auto save */
        
    if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;

        
    /* Verify the nonce before proceeding. */
        
    if(!isset($_POST['extra_content_meta_box_nonce']) || !wp_verify_nonce($_POST['extra_content_meta_box_nonce'], basename(__FILE__)))
            return 
    $post_id;

        
    /* Update the meta value. */
        
    update_post_meta($post_id'slider_box1_title'$_POST['slider_box1_title']);
        
    update_post_meta($post_id'slider_box1_text'$_POST['slider_box1_text']);
        
    update_post_meta($post_id'slider_box2_title'$_POST['slider_box2_title']);
        
    update_post_meta($post_id'slider_box2_text'$_POST['slider_box2_text']);
        
    update_post_meta($post_id'slider_box3_title'$_POST['slider_box3_title']);
        
    update_post_meta($post_id'slider_box3_text'$_POST['slider_box3_text']);
        
    update_post_meta($post_id'slider_box4_title'$_POST['slider_box4_title']);
        
    update_post_meta($post_id'slider_box4_text'$_POST['slider_box4_text']);
        
    update_post_meta($post_id'content_box1_title'$_POST['content_box1_title']);
        
    update_post_meta($post_id'content_box1_text'$_POST['content_box1_text']);
        
    update_post_meta($post_id'content_box2_title'$_POST['content_box2_title']);
        
    update_post_meta($post_id'content_box2_text'$_POST['content_box2_text']);
    }
    So the fields render fine and I can edit them but the save function just doesn't seem to be working.

    Thanks in advance

  2.  


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:19 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com