Here’s a solution using a [shortcode] which doesn’t rely on running PHP inside of the content area. Here are the docs for get_post_meta() which show how that function should be called.
add_shortcode( 'buy_status', 'wpse249289_buy_status' );
function wpse249289_buy_status( $atts ) {
$output="";
if ( ! get_post_meta( get_the_ID(), 'buy_status', true ) ) {
// Post meta value for key buy_status is false
$output .= '<h5 style="text-align: center;display: block;">';
$output .= 'Sorry, this piece is sold.';
$output .= '</h5>';
} else {
// Post meta value for key buy_status is not false
$output .= '<h5 style="text-align: center;display: none;"></h5>'; // Not sure why you'd want to output anything
}
return $output;
}
Related Posts:
- How to update custom fields using the wp_insert_post() function?
- Alter query on edit.php
- Permanently remove first image from posts
- Insert code when users come from an specific referer
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- Go to / Scroll to Password Field on WordPress Posts After Submit With Message(s)
- New Plugin Review
- Use template for posts with a particular category grandparent
- How to migrate the posts from an old custom legacy blog to a new WordPress website?
- Styling images coming from another blog
- Exclude posts from homepage having a specified tag
- “before delete post” action fire when the post is updated?
- How can I use wp_query to show all product data using just the products ID?
- Retrieving Author ID in wp-admin area
- Trying to add attribute to my posts’ featured image
- Can’t get wp_insert_post to work
- Why not yield/iterable in posts interface?
- Best practice for migration friendly images in posts/pages?
- 200 Rewrite blog post links
- Loop through categories and display posts title under each dropdown
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Second transition_post_status hook fired instead of the first
- How to store post ID’s in cookie or session to display the same posts later
- Post repeating with infinite scroll
- 404 error when I acess the second page of post-type
- Which PHP page is the Default Posts Page
- retrieve post data and insert it in seperate static html page without WordPress
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- Returning data instead of echoing/printing
- Display related posts without a plugin
- Counting Search results, and displaying the offset per page
- Function works everywhere, how to keep it to execute when creating a new post
- Copy taxonomy terms from one post to another programmatically
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- How to catch wordpress post ID when it’s published
- WordPress query undefined offset in loop
- Find Site ID From WP_Post
- WP_Query: getting posts where custom field exists
- Reading settings in the home page precisely home.php
- WordPress upload file size error even after raising php limits
- get post id from wp_insert_post for get_template_part
- Displaying list of posts in category page
- How can I get “Previous” and “Next” to show in the navigation besides the links?
- array_rand not working correctly?
- WP_Query() load selected post
- how to edit a specific post slug using a php code?
- How to pick “full/thumbnail” images in the loop?
- Why when I create a new post I found 2 record related to this post into the posts database table?
- Saving a post ID to use in a form elsewhere on website
- Prevent post from being published and show error
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- remove specificly the last tag in all posts
- Pagination at category doesnt work with same name of page
- Add posts to custom table in database instead of wp_posts
- understand what code is doing when prepending /blog
- How to show categories and date on posts
- duplicate posts with ajax load more wordpress
- Query on a repeater date (acf)
- Time Stamp In A WordPress Post Title That Does Not Keep Refreshing
- Trying to show the category of a post in the post display
- Split post or page content in two or more columns
- Check the database for a postmeta field
- Show a text if the post has written by author user role in WordPress
- Send POST request to Flask app from functions.php file
- Change upload URL by mime type
- How to pull date/time in french format for wordpress post?
- Send Notification after post published was working but stopped after the last WP update
- WordPress post insertion from PHP file
- How to display last whole post on the homepage
- How to insert text into post based on category – via single.php file
- Make sticky post with FacetWP
- WordPress Single Post Pagination Numbered and Navigational
- Getting page / post URL on publish and / or update
- Let user select the number of posts shown per page jquery error
- Add wp posts to cutom masonry grid
- Generate random access token to a post page
- Displaying 3 Category Posts differently
- Only display notification on single post
- Get posts associated with media attachment
- ‘posts_per_page’ in costum page type
- Passed variable gets undefined variable error on insert on next page
- Weird Behaviour: Not all WordPress Posts appearing
- Dynamic form variables for post meta
- List of child pages fetch next results at link click
- Automatically create a loop for post ID
- Why does WP_Query show only the same post even with different categories and endwhile?
- Auto create description in post
- Different image and background color depending on page type
- HOW TO Insert Existing PHP Code to WOrdPress
- Query posts by custom fields (object post)
- How to modify this function to exclude also the post belonging to a specific category?
- How to list all the posts in a personalized page? WordPress
- Excerpt all post content Content Same Size without word cutting off
- Set post to draft if matching word is found in the post
- Disable single posts, but keep archive
- How do I get a function to work in single.php
- Count the number of matching post names in foreach loop
- Need Help With Making Full-Width Template for Blog Posts (common methods aren’t working)
- How to get ACF field to show up on all posts on front end?
- Category Attachment Pagination 404 Error on 2nd Page