You could use the empty
function inside your if
as such :
<?php if( empty( get_post_meta( $post->ID, 'price_list_category1', true ) ) ) : ?>style="display:none;"<?php endif; ?>
The above returns an error, you should assign the return value to a variable. See my edit below.
Warning
empty
might not be the best option depending on the values you store in the meta. Values like false
, 0
etc… will be considered empty.
Check the PHP manual for the full list of values that are considered empty.
Edit
You can try assigning the meta to a variable, and using that in the if
statement.
<?php
$price_list = get_post_meta( $post->ID, 'price_list_category1', true );
?>
And then…
if( empty( $price_list) ) : ?>style="display:none"<?php endif; ?>
Related Posts:
- Get posts by meta value
- post formats – how to switch meta boxes when changing format?
- How get post id from meta value
- Safe to delete blank postmeta?
- Meta compare with date (stored as string) not working
- How to update/insert custom field(post meta) data with wordpress REST API?
- get_post_meta returning empty string when data shows in the database
- publish_post action hook doesn’t give post_meta_data
- How to access the post meta of a post that has just been published?
- How to get all term meta for a taxonomy – getting term_meta for taxonomy
- Should I sanitize custom post meta if it is going to be escaped later?
- Front-end update_post_meta snippet displays white screen?
- Query between two meta values?
- How to get meta value in wp_attachment_metadata
- Clean up output added via wp_head()
- List posts under meta_value heading
- loop through all meta keys with get_post_meta
- get_post_meta returns bool(false)
- WP_POSTMETA changes site crash
- meta_post_meta return value 1
- How to use post_id with a Class?
- Saving html into postmeta without stripping tags – safe?
- How to show Published date and/or Modified date
- wp_update_user isn’t instantly?
- INSERT ON DUPLICATE KEY UPDATE failes in postmeta table
- How to use update_post_meta inside wp_trash_post
- “update_post_meta” not working in “wp_insert_post_data” hook
- replacing the_autor or make callback
- Display All Custom Post Fields and Values, Unless Empty
- Some post meta fields stop saving after a few successful saves
- How to create a meta_query to get all posts with a specific meta data?
- hide posts with specific meta data from admin page
- Post MetaTable Overload
- Custom RSS Feeds & Post Meta Data
- Add Embed.ly API objects to post_meta on update
- Editing does not change post_name
- Compare string with post id in wpdb and do stuff when match is found
- get_post_meta not extracting title,permalink and posttype
- How to selected which tags to print, instead of printing the whole tag list?
- Display get_post_meta if contains value
- Save post meta foreach loop
- query posts and split meta information into separate div’s
- Should I save this mulit dementional arary as one post meta?
- Sort Posts By Custom Field Date?
- Difficultly changing date format in post meta value
- Remove last character in get_post_meta
- add unique string as custom-field to every post
- How do I insert a new meta key / value pair, but only if another meta key is present?
- mass delete posts based on metadata
- How to obtain a group of post meta and assign each meta to other variables?
- Gutenberg featured image checkbox – checkbox not correctly set on editing page reload
- Duplicate rows in meta table, any known relations in WC?
- Adding Custom MetaData
- Suggestion to make posts have multiple associated items
- How to properly use oneOf and anyOf in Rest Schema?
- update_post_meta in loop changing ALL values
- wordpress is_front_page() issue
- Why is my get_post_meta not properly calling the custom field when attempting to embed a YouTube video?
- How to echo value of a meta select box to the browser
- How can I use ‘orderby’ => ‘meta_value_num’ to order by the numerical value even if the value starts with a word?
- New Table vs Post / Comment Meta
- How we can get “get_post_meta” of specific user who added it
- help to decipher wp metadata
- How do I add a fixed value to get_post_meta();?
- Add post’s category as a meta tag to the post
- How can I query for posts using a date stored in post-meta?
- I can not display meta value in extras.php and template-tags.php
- update_post_meta() updating nested array in Multidimensional array with empty sub-array
- get specific values from WordPress meta_value
- Is duplicate `_wp_attachment_image_alt` meta key allowed?
- Sorting my posts on homepage my specific value in post_meta table
- How can i set media attachments to the author of the post or page for already existed posts with attachments
- Strict comparisons problem when using boolean post meta
- How to get posts by meta value as multi-dimensional array?
- Add post meta data date to event
- Check if any meta on the post has value then display content
- How to modify default meta link format
- Combine meta query and give a specific meta query a higher priority
- Something adding an excessive meta description
- gettext localization is not working
- Move Entry Meta Above Title in Archives (Genesis + Brunch Pro)
- how to query posts using value in meta post array
- Why doesn’t wp_oembed_get() for the video post format not work?
- Custom Meta Fields that are Echo’d are removed on post update?
- How to add dynamic content in title and meta description in wordpress theme for homepage, post page, category, tag and pages
- How to call get_post()?
- add_post_meta only adding 1 character
- Create a Gallery and update Post Parent of Attachment Images
- Update event post meta each day automaticaly
- Advanced Custom Field — grabbing post_meta from previous post
- Posts with no meta field do not appear when sorting by meta field
- How do I delete element from a serialized array upon deletion of a post?
- How to create a link for wordpress meta datas?
- Get meta information from post parent
- Counting number of identical meta keys
- wp_postmeta store multiple values in one key [closed]
- query with custom field
- Using Form to alter PHP variable [closed]
- Chance post id into post name
- get_post_meta() returns nothing in save_post, publish_post, wp_after_insert_post