'; echo ''; echo ''; //echo ''; //echo ''; // echo ''; } $prefix = 'dbt_'; $saveddata = array(); $meta_box = array( 'id' => 'my-meta-box', 'title' => 'Ask a question', 'page' => 'post', 'context' => 'normal', 'priority' => 'high', 'fields' => array( array( 'name' => 'Checkbox', 'id' => $prefix . 'checkbox', 'type' => 'checkbox' ) ) ); add_action('admin_menu', 'mytheme_add_box'); // Add meta box function mytheme_add_box() { global $meta_box; add_meta_box($meta_box['id'], $meta_box['title'], 'mytheme_show_box', $meta_box['page'], $meta_box['context'], $meta_box['priority']); add_meta_box($meta_box['id'], $meta_box['title'], 'mytheme_show_box','page', $meta_box['context'], $meta_box['priority']); } function mytheme_show_box() { global $meta_box, $post; foreach ($meta_box['fields'] as $field) { $meta = get_post_meta($post->ID, $field['id'], true); echo 'ask question'; } } add_action('save_post', 'mytheme_save_data'); // Save data from meta box function mytheme_save_data($post_id) { global $saveddata; global $meta_box; $options = array(); if ( $the_post = wp_is_post_revision($post_id) ) $post_id = $the_post; if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } foreach ($meta_box['fields'] as $field) { $old = get_post_meta($post_id, $field['id'], true); $new = $_POST[$field['id']]; if ($new && $new != $old) { update_post_meta($post_id, $field['id'], $new); $options[0] = $post_id; $options[1] = $new; update_option('askquestion'.$postid,$options); } elseif ('' == $new && $old) { delete_post_meta($post_id, $field['id'], $old); $options[0] = $post_id; $options[1] = $new; update_option('askquestion'.$postid,$options); } } } add_action('wp_head', 'head_fun'); function head_fun($postid) { echo ''; $options = get_option('askquestion'.$postid); if (is_single() || is_page()){ if($options[1] == 'on'){ add_filter('the_content','add_content'); } else { remove_filter('the_content','add_content'); } } } function add_content($content) { global $post; $ID = $post->post_author; update_option('cpid',$ID); update_option('cpostid',$post->ID); return $content. '