You are already doing what you need to do, but in another context.
$value = get_post_meta($post->ID, 'rating', true);
Take that value and format it for display.
Edit: I installed your whole block of code. You are storing you key, not your ratings value. You need to access that $ratings array again to pull the value.
$ratings = array(
1 => ' G ',
2 => ' PG ',
3 => ' R ',
);
if (!empty($ratings[$value])) {
echo '<p>Content Rating : '.$ratings[$value].'</p>';
} else {
echo '<p>Content Rating : Unrated</p>';
}
However, even before I spotted the problem I was seeing content echo. “Content Rating: 1” instead of “Content Rating: G”. I don’t know why you claim to see nothing. If you still see nothing, something is wrong but not with this code.
I made no changes to your original block of code.
Related Posts:
- Get post meta retrieving wrong value
- How can I create a menu items from meta box based on users input
- How to change the case of all post titles to “Title Case”
- Dynamically add id to heading tags
- Update all posts automatically when using post_meta
- Restrict users from editing post based on the age of the post
- Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
- $post object is null
- Function to show random posts from a category
- Redirect to another page using contact form 7? [closed]
- Which PHP page is the Default Posts Page
- How to rate a post from Admin Side / Manually?
- Adding a user’s ID behind the tag ref link address
- saving/reading custom field value does not work – no value gets POSTed
- How To Use Custom Fields With .mp3 Links
- How to limit the number of results for all query_posts on mysite
- User driven content problems
- List direct children of page
- How *not* to show the last post on the latest posts list
- Adding a content rating system
- How to update custom fields using the wp_insert_post() function?
- Add custom field automatically (add_post_meta) with value based on number of words of article
- Create cron job without a plugin?
- Global $post not working in OOP function WordPress
- How can I get a post field value using javascript?
- Automatic value for custom fields for posts
- Getting current post ID in functions.php
- How to rename “Publish” metabox title in post screen
- Understanding and using metaboxes in posts
- Accessing post->ID outside of the loop for listing child pages
- how to set beforsend option in wordpress ajax methods
- Action hook for new pending posts?
- Uppercase first sentence in every post
- Add icon/badge next to posttitle of specific category
- Query all posts of a custom taxonomy term
- Ajax posts filter by date, comments, top views, top likes
- Duplicating Table of Contents for Paginated Post
- Prepend or add an Image to the content of a Post
- Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
- Why content_arr[‘extended’] removes paragraph tags?
- Passing the custom field values in the wp_get_current_user array function
- Guest Author – How to display posts on /author/ archive page
- Display post category in foreach loop with category link
- WordPress Custom Fields (Checkboxes with multiple values)
- Load post attached images on a single page site with fancybox
- WP_Query orderby not working with meta_value_num and menu_order
- Why WP_Query(‘showposts=5’) shows only 1 post?
- How can I sort posts by the date and a custom meta field?
- Most liked page not displaying posts
- How to make number of blog posts a custom field?
- Exclude category from
- Get post id in a function when edit/add a post
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- How to display Common posts from specific Tag & Category with Shortcode
- Setting posts_per_page for taxonomy term template
- Change post order random through out the entire WordPress
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- get_post_meta not working on publishing
- Firing schema via code in functions.php doesn’t work
- How to display the link (title) and thumbnail post?
- How can I add extra word in permalink when someone click download button?
- Force the “Choose from the most used tags” meta box section to always be expanded
- Show the content that is after the excerpt using child theme
- Automatically add custom fields value to wordpress post
- How to allow users to post only in certain category and hide elements from edit page?
- Is there a way to notify specific users when new posts are published to specific pages?
- 3 Slashes appear after Apostrophe in custom fields after updating product-site
- How to do set post permalinks using 6 digit random unique function?
- Can’t get buddypress notifications in front-end; why do I get this error?
- How do I display some posts fully on the homepage, and some as an excerpt only?
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- MySql query to get posts with all meta and terms
- Categories list into registration form
- Send post id through ajax and get the post content back
- Add a custom meta box in the post options that loads some html code in the header
- Creating a post from data returned from HTML form
- Display post x of y within category
- Force authors to Preview a post before publishing
- Trying to retrieve post meta
- WordPress Automatic Filename Changer
- Query Posts With Over 1000 Views
- Cannot retrieve a custom RSS field from posts
- List authors with the last post title and order by last post date
- Hooking into the post editing screen for an existing page only
- Query Posts by Custom Field
- Display post category in foreach loop
- Order posts alphabetically: how to set order=asc in mysql query?
- Page template is accessing the incorrect posts?
- Customize rel=canonical tag for single blog post
- Change all author links in Blog roll
- How to I retrieve the ID from the Posts page?
- Function works everywhere, how to keep it to execute when creating a new post
- How to check if a PHP string is different than meta field?
- Can’t save php string to a custom field
- disable Tab post on nav-menus page (Admin)
- Why does this update_post_meta function not delete the custom field itself?
- How to show/hide php table rows based on the content of custom fields
- Adding bootstrap classes to video shortcodes
- Pagination on Custom Post
- Every second post different class in blog view