• gryms

    (@gryms)


    Hi!

    I’m making a video site which feautures videoes and also a live broadcast. The broadcast will not be available at all times so I am trying to add a text on the front page when the broadcast is available by using a checkbox. This is the code i have so far:

    function true_add_a_metabox() {
        add_meta_box(
            'live_metabox', // metabox ID, it also will be it id HTML attribute
            'Livesending', // title
            'true_display_metabox', // this is a callback functions, which will be print HTML of our metabox
            'post', // post type
            'normal', // position of the screen where metabox shoul be displayed (normal, side, advanced)
            'default' // priority over another metaboxes on this page (default, low, high, core)
        );
    }
    
    add_action( 'admin_menu', 'true_add_a_metabox' );
    
    function true_display_metabox($post) {
        /*
         * needs for security checks
         */
        wp_nonce_field( basename( __FILE__ ), 'true_metabox_nonce' );
        /*
         * lets add a simple textarea field
         */
        /*
         * add a checkbox
         */
        $html .= '<p><label><input type="checkbox" name="live"';
        $html .= ' /> Trykk her dersom dette er en livesending</label></p>';
        /*
         * print all of this
         */
        echo $html;
    }
    
    function true_save_post_meta( $post_id, $post ) {
        /*
         * Security checks
         */
        if ( !isset( $_POST['live_metabox_nonce'] ) || !wp_verify_nonce( $_POST['live_metabox_nonce'], basename( __FILE__ ) ) )
            return $post_id;
        /*
         * Check current user permissions
         */
        $post_type = get_post_type_object( $post->post_type );
        if ( !current_user_can( $post_type->cap->edit_post, $post_id ) )
            return $post_id;
        /*
         * Check if the autosave
         */
        if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
            return $post_id;
    
        }
        return $post_id;
    }

    Does anyone have any tips or tricks to get this to work. My meta box displays fine when writing a post, but I am not able to display any content on the front page, and the checkbox does not save correctly aswell. Thank you for your time and any help will be appreciated.

  • The topic ‘Meta box to display content on front page’ is closed to new replies.