will be id for add_meta_box 2. Post Strength Mode => will be the Title for the meta box and it will be displayed in the admin dash board 3. buffercode_inner_post_mode => function to go with our busines logics. */ add_meta_box( 'buffercode_post_mode_id', __( 'Post Strength Mode', 'buffercode_box' ), 'buffercode_inner_post_mode', $buffercode_locations ); } } #registering our meta boxes in admin dash board. add_action( 'add_meta_boxes', 'buffercode_post_mode' ); function buffercode_inner_post_mode( $post ) { // Add an nonce field so we can check for it later. wp_nonce_field( 'buffercode_inner_post_mode', 'buffercode_inner_post_mode_nonce' ); /* Get the value previous value from the database to display in the admin dashboard */ $value = get_post_meta( $post->ID, 'buffercode_meta_value_key', true ); #label to show the field Select the Difficult of this Post echo ' '; ?> ID, 'buffercode_meta_value_key',true); //Get the selected value from the admin dashboard if($meta_value != 6) { //Getting New Text Field Value $bc_text_field_value = get_option('bc_text_field'); //Getting the Combo Box value above or below $bc_above_below_value = get_option('bc_above_below'); //Getting star color value $bc_star_color_value = '#'.get_option('bc_star_color'); //Getting Star size $bc_star_size_value = get_option('bc_star_size'); if($bc_star_size_value == 'H1' || $bc_star_size_value=='H2' || $bc_star_size_value=='H3' || $bc_star_size_value=='H4' || $bc_star_size_value=='H5') $bc_star_size_value = 'div class="'.$bc_star_size_value.'"'; //Getting Post or Home or Both value $bc_star_locationh_value=get_option('bc_star_locationh'); $bc_star_locationp_value=get_option('bc_star_locationp'); //Default value has been assigned for text, If text box is empty if(empty($bc_text_field_value)){ $bc_text_field_value="";} if(is_null($bc_above_below_value)){ $bc_above_below_value='above';} //seting default star color to black if($bc_star_color_value=='#'){ $bc_star_color_value='#000';} //setting default start size to H2 if($bc_star_size_value==""){ $bc_star_size_value='div class="H2"';} //Computing the value for Home or Post or Both if($bc_star_locationh_value=="" && $bc_star_locationp_value=="") {$homeonly=0;$postonly=0;} if($bc_star_locationh_value==1 && ($bc_star_locationp_value ==1)) {$homeonly=1;$postonly=1;} if($bc_star_locationh_value==1 && $bc_star_locationp_value=="") {$homeonly=1;$postonly=0;} if($bc_star_locationh_value=="" && ($bc_star_locationp_value==1)) {$homeonly=0;$postonly=1;} // Default values Ends $original = $content; //Orignial Content //$content .= $original; switch($meta_value) //checking for the value selected { case 1: //if value 1 selected the one star will be displayed $new_content = ''.$bc_text_field_value." <".$bc_star_size_value." >☆"; break; case 2: //if value 2 selected the Two star will be displayed $new_content = ''.$bc_text_field_value." <".$bc_star_size_value." >☆ ☆"; break; case 3: //if value 3 selected the Three star will be displayed $new_content = ''.$bc_text_field_value." <".$bc_star_size_value." >☆ ☆ ☆"; break; case 4: //if value 4 selected the four star will be displayed $new_content = ''.$bc_text_field_value." <".$bc_star_size_value." style=\"display:inline-block; margin:-20px 0px 20px 0px;\">☆ ☆ ☆ ☆"; break; case 5: //if value 5 selected the five star will be displayed $new_content = ''.$bc_text_field_value." <".$bc_star_size_value." >☆ ☆ ☆☆ ☆"; break; case 6: $new_content = ""; break; default: $new_content = "Difficulty level not set for this Post"; break; } //Show the rating on home and post if($homeonly==1 && $postonly==1){ if( is_home() || is_singular() || is_archive() || is_category() ){ //If Rating selected to display above if($bc_above_below_value=='above') return $new_content.$content; //returning the orginal content and new content else ////If Rating selected to display Below return $content.$new_content; } else{return $original;} } //Show the rating only on home elseif($homeonly==1 && $postonly==0){ if( is_home() || is_front_page() || is_archive() || is_category()){ //If Rating selected to display above if($bc_above_below_value=='above') return $new_content.$content; //returning the orginal content and new content else ////If Rating selected to display Below return $content.$new_content; } else{return $original;} } //Show the rating only on Post elseif($postonly==1 && $homeonly==0){ if( is_singular()){ //If Rating selected to display above if($bc_above_below_value=='above') return $new_content.$content; //returning the orginal content and new content else ////If Rating selected to display Below return $content.$new_content; } else{return $original;} } else{return $original;} } else { return $content; } } #filter to add the above function after the content add_filter( 'the_content', 'buffercode_meta_content' ); //////////////////////////////////////////////////////////// //Adding difficulty level star to post list admin dashboard// add_filter('manage_posts_columns', 'article_bc_columns_head'); add_action('manage_posts_custom_column', 'article_bc_columns_content', 10, 2); function article_bc_columns_head($defaults) { //$meta_value=get_post_meta($post->ID, 'buffercode_meta_value_key',true); $defaults['meta_value_col'] = 'Difficulty Level'; return $defaults; } function article_bc_columns_content($column_name, $post_id) { if ($column_name == 'meta_value_col') { $meta_value_star=get_post_meta( $post_id, 'buffercode_meta_value_key', true ); switch($meta_value_star) { case 1: echo '