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

Saving zero as meta value

if ( !$value ) evaluates to TRUE when the value is 0.

Alternative:

if ( ! isset ( $_POST['_ordre'] ) ) 
    return delete_post_meta( $post_id, '_ordre' );

update_post_meta( $post_id, '_ordre', $_POST['_ordre'] );

You don’t need add_post_meta(), the call to update_post_meta() will do that automatically.

Related Posts:

  1. Dealing with Many Meta Values, 30+
  2. How do i get value from wp_postmeta?
  3. Why WordPress choose data serialization over json_encode?
  4. What is the most secure way to store post meta data in WP?
  5. How to delete outdated, wrongly sized images in _wp_attachment_metadata?
  6. Meta query interfering with orderby relevance
  7. Migrating non-WordPress CMS to WordPress, lots of data to move — possible solutions?
  8. How to solve slow WordPress site caused by attachment_metadata
  9. Delete all post meta except featured image
  10. Is it possible to store visitors IPs in wp_postmeta table?
  11. Multiple postmeta with same name for one post in wp_postmeta table
  12. Delete all post meta except featured image Using SQL
  13. One post carries 30 postmeta values, is this too much?
  14. delete post meta from db, even if does not exist?
  15. WordPress and MySQL: how to transfer Meta_key and Meta_Value from one post_id to another
  16. Storing data for a wordpress plugin
  17. Where does the actual data stored by add_post_meta
  18. Structure of postmeta meta_value for woocommerce product download
  19. Routine to convert custom post meta from old to new value
  20. “The link you followed has expired” & “Error while saving” messages when adding new post
  21. Uknown meta entries in wp_postmeta
  22. What’s the proper way to sanitize checkbox value sent to the database
  23. Does post_meta data need to be unserialzed?
  24. Link image with data from the wpdb
  25. Custom Post Type not showing anything added by code anymore?
  26. Secure way to use name_save_pre?
  27. Compare User meta_value with Product meta_value
  28. How to save EXIF metadata in WordPress database?
  29. _wp_attachment_metadata is not being added to database when PDF files uploaded
  30. Best Practice? – Saving multiple Values as Serialized Data / Saving each Value per Row / Dedicated Table
  31. “BS_” rows in postmeta table
  32. Migrating meta_key and meta_value from old theme to new one
  33. Database structure for thousands of posts
  34. How much post meta data is too much?
  35. Custom metabox does not store data
  36. Recommended Post Structure for DB Storage
  37. SQL query : Select a thumbnail for a media
  38. Query a meta key using an array of values where the database value is a string
  39. MySQL SELECT increment counter
  40. Exclude Statement in SQL
  41. Detecting errors generated by $wpdb->get_results()
  42. wpdb update add current timestamp not working
  43. Custom form that store input in database
  44. update_post_meta and update_field ony working when saving the post
  45. Displaying content from one WP site on separate WP site
  46. Lost the `wp_options` table: what’s the best way to restore the site?
  47. Can a post ID be 0?
  48. Issue with wp_insert_post and post_content field error Could not update post in the database
  49. wp_posts – guid update
  50. Performance Gains of Relational DB Setup
  51. How to move existing WordPress wp-content folder along with database to new server and new domain name?
  52. what is the wp_5_posts table in the database?
  53. Migrating data between local and development server
  54. WordPress Database Charset/Collate
  55. store simple data in get_option()
  56. How might I retrieve a featured post image from an external WP site and display it as a link back?
  57. What is the database table for pages?
  58. Using Dynamic Data Pulled from a MySQL Table in a WordPress Page
  59. What are conventions about the schema of the $table_prefix
  60. WordPress database becoming huge. How to analyze and optimize it? fear of running out of memory
  61. BuddyPress: What’s the use of wp_bp_xprofile_data table and how does it get updated? [closed]
  62. What is an efficient way to query based on post_meta?
  63. What’s the most efficient database method to add and query usermeta?
  64. Is database safe after merging a branch of a more recent version over an older one?
  65. Hook to be used when creating a database table
  66. Where is custom template file chosen for a post stored in the DB?
  67. Large database causes slow load
  68. Safe way to find last inserted id in a table?
  69. Database slowdown after update to 3.4.1
  70. WooCommerce sku location in DB
  71. How to insert data into MySQL database from the form created in WordPress site
  72. Which is best in the following scenario : post_meta vs custom table vs parent/child posts
  73. Emoji support and MariaDB 10.0.30-
  74. WordPress DATABASE Update Manually?
  75. order by multiple meta_keys?
  76. I don’t see site_url and home_url fields in wp_options table (phpMyAdmin)?
  77. Which is more efficient? Using usermeta, or creating a new MySQL table?
  78. How do I copy a wordpress database?
  79. Export all content from wordpress
  80. Import live site to local setup without access to live site
  81. A field with dashes in the slug [closed]
  82. Creating a Video Content Page (how to use query strings in wordpress)- Help!
  83. Modify Database in Multi-Site wp_usermeta table
  84. Form Data not getting stored in WordPress database
  85. Hook directly into query execution
  86. Best way to tell if a user account is active, using the database only
  87. $wpdb doesn’t like to store arrays
  88. Connect to a remote database for wordpress in my own hosting server
  89. Handling large N data in WordPress
  90. Get Meta Key Value While Saving Post
  91. How to replicate a user plugin made table value, to this user’s custom meta table value?
  92. How can I convert postmeta from unserialized to serialized?
  93. Catalina an MAMP Database Conenction Error
  94. What Is the Proper Way to Merge Usermeta Table to a an existing WP Database?
  95. Importing CSV into database table not working?
  96. A MySQL DB within a MySQL DB
  97. Is there a way to recover the table wp_term_relationships?
  98. Trouble Migrating all data blog from WordPress.com to WordPress.org
  99. “Database Connection Error” upon install in Apache VirtualHost document root.. Why did this happen? [closed]
  100. How Can I Put Meta_Compare in the Database-Query?
Categories Database Tags database, meta-value, post-meta, save-post
Query Posts With Over 1000 Views
How do I display a custom field from a custom taxonomy in single.php?

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