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
- Add a checkbox to post screen that adds a class to the title
- disable WP automatically inserted line breaks after an image
- Getting the post_id in wp_ajax function
- delete post also attachments
- Publish pending article from front end with a button?
- How to call function within a page/post, to dynamically generate content?
- I am trying to create a simple frontend form for posting
- HTML code in Custom field
- How to show posts rank based on custom field value
- Force update all posts in custom post type, no content changes
- Search widget breaks when using multiple loops?
- Change post format using custom field
- Disable REST API for a user ROLE
- Add confirmation popup on “Move to Trash”
- How can I make existing custom fields easier to edit/add in my theme?
- How to get Advanced Custom Field Value According using POST ID? [closed]
- Advanced Custom Fields – Storing array value for further usage
- How can I list random authors from current post category?
- Disable single post page
- Add custom field automatically (add_post_meta) with value based on number of words of article
- Global $post not working in OOP function WordPress
- Getting current post ID in functions.php
- Understanding and using metaboxes in posts
- Accessing post->ID outside of the loop for listing child pages
- Passing the custom field values in the wp_get_current_user array function
- Load post attached images on a single page site with fancybox
- Setting posts_per_page for taxonomy term template
- Change post order random through out the entire WordPress
- How to display the link (title) and thumbnail post?
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Page template is accessing the incorrect posts?
- Customize rel=canonical tag for single blog post
- How to check if a PHP string is different than meta field?
- disable Tab post on nav-menus page (Admin)
- Get post ID from a link
- How to only publish posts with image in it
- Custom meta box values are not getting saved for my custom post type
- WP_Query: getting posts where custom field exists
- WP All Import / Update stock quantity from multiple XML files
- Output Post with ACF Fields into other Post
- get post id from wp_insert_post for get_template_part
- Using system date format
- Unable to render custom field after attempt to generate a list of recent post in page template
- Hide a div when a custom field is empty
- Conditional On custom field plugin metabox
- Defining ‘last’ class on foreach blog posts
- Categories Listing and Highlighting current category item
- Help Combine These Two PHP Codes
- Help on conditional statement to accompany wp_insert_post function please?
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- How to save template data into wp_post table (post_content column)
- Custom Fields – How to get the list of a specific active widget each time it rendered
- shortcode // get posts by ids
- Products listing check if meta checkbox is checked
- Is it possible to update the dataset using update_post_meta
- WordPress hide post from custom post-type on a single page
- Find most used words in post titles
- $post->post_content empty while all other properties are correct
- Saving canvas generated image when saving post causes 404 error
- Get field in readable word
- Replace Tag Keyword With Link Within Post Content
- Getting page / post URL on publish and / or update
- How to change number of posts shown on homepage vs other pages?
- Weird Behaviour: Not all WordPress Posts appearing
- How do I display a full post, not just an excerpt?
- Attaching global meta to custom fields
- wordpress radio button on single post page
- First Custom Post Custom Fields Empty After New Custom Post
- Posts sortable column not sorting properly for custom field numbers
- Exclude a ‘portfolio’ custom category?
- wp trim function not working
- get value from post to sidebar
- Insert Shortcode exactly at the end of the content
- display last post modified date in genesis child themes
- Appending an ACF custom field to the page title
- Custom Post-Rename Function Does Not Function in WordPress 6.x
- WooCommerce: write featured image dimensions to custom fields in product’
- Read more opens attachment
- transition_post_status hook, works – but not if the post is new
- How to sort posts alphabetically based on a specific parent category