Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

If custom field doesn’t exist, or exists and it’s true show title?

empty checks for several things:

  • “” (an empty string)
  • 0 (0 as an integer)
  • 0.0 (0 as a float)
  • “0” (0 as a string)
  • NULL
  • FALSE
  • array() (an empty array)
  • $var; (a variable declared, but without a value)

In short, you are running a check if the value evaluates to false or does the value evaluate to true. Either way it will always evaluate to true.

Now I don’t know what the function vf_get_meta returns for empty values. If you look at core get_post_meta function, it returns either an empty array or an empty string when the single flag is set to true.

I think the best rewrite will be this:

if ( vf_get_meta($post->ID, 'page_options', 'show_title') !== false )

We are saying, as long as it is not set to false, do it. You’ll notice that I used !== instead of !=. The !== is the “Not Identical” comparison instead of the != “Not Equal”. PHP will convert certain values into a boolean true or false for the equality comparison. Sometimes you’ll hear people say a value is “truthy” or “falsey” reflecting how it will be convert to a boolean value.

Related Posts:

  1. How to store multiple custom meta box
  2. How to update custom fields using the wp_insert_post() function?
  3. How to display multiple Post meta_key/meta_values by SQL query
  4. How to use multiple query with same meta key
  5. How can update custom meta for all posts
  6. Use ajax to update_post_meta
  7. how to increase custom post value by one most efficiently?
  8. How can I create a list of page titles from custom meta values?
  9. Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
  10. How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
  11. Need Help Fixing My Iframes [closed]
  12. Trying to retrieve post meta
  13. Is it possible to retrieve all posts with a certain value for metadata?
  14. Saving zero in meta box
  15. Non-Closing PHP Query in WordPress Loop
  16. Find a way to retrive data updated through metabox plugin to web page
  17. Why does this update_post_meta function not delete the custom field itself?
  18. how to get serialized post meta
  19. WordPress loop by meta key that is an array? and how loop multiple arrays
  20. Order a WP_Query by meta value where the value is an array
  21. Add a custom class to the body tag using custom fields
  22. Define category ID using get_post_meta
  23. Unable to Call More than One Meta Box Output
  24. Hide a div when a custom field is empty
  25. Post meta select input, if statement
  26. Display background color or image with custom meta box?
  27. Meta boxes only displayed when editing normal (default wp post_type) posts
  28. WordPress stripping out custom field tags
  29. Order category posts by last word of custom field
  30. Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
  31. How to update custom fields when post is published?
  32. Unable to update the meta boxes with multiple fields
  33. WP post meta – for loop inside for loop
  34. When working with a post, almost all wp_postmeta are deleted
  35. Updating Lat and Lng of posts automatically gives sporadic results
  36. meta field for numerous links
  37. Custom fields changes the formatting of metabox input
  38. WordPress AJAX load post metadata in modal
  39. custom field meta-box with dropdown/autocomplete
  40. Where can I find the code for the menu page meta boxes?
  41. PHP Puzzle: Unique Styles with PHP loop
  42. Display custom meta box in my template file
  43. Metadata on the WP_Post object
  44. Dynamically added custom fields not displayed on WooCommerce email notifications
  45. How to check post meta isset or not empty during publish/save post?
  46. Delete images from media library when user deletes an image from ACF Gallery
  47. Updating Metadata with Shortcode
  48. get value from get_post_meta then reuse it in another get_post_meta
  49. Adding a custom meta field with default NULL value which is not selectable
  50. How do you save the values from custom fields to a products data
  51. Custom Post Type meta data getting deleted on bulk editing taxonomies
  52. Add a Metabox checkbox to the Page Edit screen of wp-admin , which only certain roles can see and Makes only certain roles able to Edit said page
  53. Checkbox doesn’t save inside metabox
  54. How can I add diffrent editable text fields?
  55. Display custom field value in woocommerce variable product via jQurey
  56. Dropdown category field inside repeatable metabox
  57. Include custom fields in search
  58. Create shortcode for metabox gallery
  59. update_term_meta() only updating once on certain meta keys
  60. Products listing check if meta checkbox is checked
  61. Trying to update Woocommerce meta values
  62. Loop for recently (updated_post_meta) posts?
  63. How to add and subtract user meta values after post meta update
  64. Is it possible to update the dataset using update_post_meta
  65. Display metabox galleries on specific page template in admin editor
  66. get_post_meta shortcode returns empty field
  67. Block error message in foreach loop when looping through ACF field
  68. Update Images after edit via php
  69. Hide a div if the fiels is empty
  70. Setting up a cron job to auto update a custom field
  71. How to improve my non-unique metadata MySQL entries?
  72. How to Call on WordPress Custom Fields without a Plugin
  73. Set class if a meta value is set within post archive
  74. Inserting a class on before_widget if checkbox is checked
  75. No more get_option(‘date_time’) in WordPress 5.5?
  76. Query on a repeater date (acf)
  77. Delete post meta by serialized meta value
  78. Using zip code to display custom data in Admin Order Details
  79. Generating 3 random numbers and saving them in database
  80. WordPress Blocks, setAttributes not saving
  81. Where does php code to load data go?
  82. ACF – Can’t get custom post type by taxonomy
  83. What is the correct way to search 3 custom fields only in WordPress?
  84. wp_get_nav_menu_items() with ACF
  85. Save custom field on WP_List_Table
  86. Show a text if the post has written by author user role in WordPress
  87. Hide author from search results meta, still display date and categories
  88. Fix common misspellings/errors based on array of replacements
  89. Sum All the Post Meta of Published posts of Current Logged in user
  90. How do I get the value of a current user’s custom field?
  91. update_post_meta Not Processing Array Data (Not Sure What I Am Missing)
  92. Trying to retrieve meta values from three different meta keys and display in rows
  93. Allow HTML in Custom Metabox area
  94. add ‘publish metabox’ to Gravity forms edit page/form area
  95. Get meta values from parent post and save in child post
  96. Reverse Cross-Sells (WooCommerce)
  97. Meta Box clears saved field content
  98. Custom field metabox not showing in back-end
  99. custom fields anchor points php
  100. Creating a “Related Meta” type field?
Categories PHP Tags custom-field, metabox, php, post-meta
I am trying to get metabox image with custom size
Second foreach loop breaking (Posts2Posts)

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress