rating articles for internal purposes

My solution to this question would be to add a custom field / metabox to all of your posts where you can select a desired rating from a drop down menu.

I would also then add the internal rating that you assign to post within the posts list screen so you can see at a glance each posts rating instead of having to click “edit” to see whether a post has a rating or not. If a post has no rating then it will list “Not rated”.

I in fact do something very similar on one of my sites and here’s some basic code that will help you achieve that…

Here are the two simple steps.

1) Paste the following into your functions.php file which will create a drop down custom field called Internal Rating (NOTE you can change the values of your drop down menu to suit your purpose, be it descriptive words like in my example or a number based rating);

add_action( 'add_meta_boxes', 'add_internal_rating' );    

function add_internal_rating() {

    add_meta_box('wpt_internal_rating', 'Internal Rating', 'wpt_internal_rating', 'post', 'normal', 'high');
}
// The Internal Rating Metabox 
function wpt_internal_rating() {
    global $post;
    echo '<input type="hidden" name="ratingtmeta_noncename" id="ratingmeta_noncename" value="' .
    wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
    $location = get_post_meta($post->ID, '_rating', true);
    echo '<select name="_rating">
    <option value="good" ' . (selected( $location , 'good', true)) . '>Good</option>
    <option value="bad" ' . (selected( $location , 'bad', true)) . '>Bad</option>
    <option value="ugly" ' . (selected( $location , 'ugly', true)) . '>Ugly</option>
    </select>';
    }
// Save the Metabox Data
function wpt_save_ratings_meta($post_id, $post) {

    if ( !wp_verify_nonce( $_POST['ratingmeta_noncename'], plugin_basename(__FILE__) )) {
    return $post->ID;
    }

    if ( !current_user_can( 'edit_post', $post->ID ))
        return $post->ID;

    $ratings_meta['_rating'] = $_POST['_rating'];

    foreach ($ratings_meta as $key => $value) { 
        if( $post->post_type == 'revision' ) return; 
        $value = implode(',', (array)$value); 
        if(get_post_meta($post->ID, $key, FALSE)) { 
            update_post_meta($post->ID, $key, $value);
        } else { 
            add_post_meta($post->ID, $key, $value);
        }
        if(!$value) delete_post_meta($post->ID, $key); 
    }
}
add_action('save_post', 'wpt_save_ratings_meta', 1, 2);

2) Next you want to add the following code to your functions.php file also, which will show the Rating post column on your Posts list screen;

    if ( !function_exists('internal_rating_column') ) {

        function internal_rating_column($cols) {
        $cols['rating'] = __('Rating');
        return $cols;
        }

        function internal_rating_value($column_name, $post_id) {

        if ( 'rating' == $column_name ) {

        $rating = get_post_meta( $post_id, '_rating', true );

            echo $rating;
            } else {
            echo __('Not rated');
            }
        }
    }

    add_filter( 'manage_posts_columns', 'internal_rating_column' );
    add_action( 'manage_posts_custom_column', 'internal_rating_value', 10, 2 );

The great thing about using a custom field to solve this issue is that you can query the data held within your Internal Rating field not only in the back end but also in the front end and although you don’t have a need for it right now, you may in the future wish to query that value somewhere in your front end theme. That ability is there, if the need ever arises.