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

How can I tell if a post has been published at least once?

We can do this by storing the value into postmeta when post is published first time.

function save_ispublished( $post_id ) {

    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
        return;

    $published_once = get_post_meta( $post_id, 'is_published', true );

    // Check if 'is_published' meta value is empty.
    if ( ! empty( $published_once ) ) {

        $published_once="yes";
    }

    // store is_published value when first time published.
    update_post_meta( $post_id, 'is_published', $published_once );
}
add_action( 'save_post', 'save_ispublished' );

you can check it by get the meta value.

$is_published = get_post_meta( $post_id, 'is_published', true );

if( $is_published == 'yes' ) {

    /*
    * Actions if post is already published atleast once.
    */
}

Hope this help !

Related Posts:

  1. How can I retrieve multiple get_post_meta values efficiently?
  2. How to batch update post content with custom post meta value
  3. What Can I Use To Add A Custom Button Between Publish button and Move To Trash?
  4. Using radio button meta data from a custom meta box
  5. How to rename “Publish” metabox title in post screen
  6. Meta value does not save for scheduled posts
  7. Calling Different Custom Post Timestamps in a table
  8. How to I retrieve the ID from the Posts page?
  9. How to save meta checkbox WordPress
  10. Updating post meta for checkbox
  11. Adding a meta box to determine the sidebar [closed]
  12. Simple Custom Metabox Not Saving
  13. Bulk Post update_post_meta
  14. How to check if post meta key exists or not in wordpress database
  15. add action only on post publish – not update
  16. How to add category to: ‘wp-admin/post-new.php’?
  17. How to prevent posts from being published too close to each other?
  18. Code to make a post sticky
  19. Is it possible to Schedule Attachments in WordPress?
  20. How to allow hidden custom fields to be added from wp-admin/post.php?
  21. Elegant way to include only published posts with get_objects_in_term()?
  22. Can I force a metabox to be in one column?
  23. How to add a new tab to page editor
  24. Listen to Post action
  25. Export WordPress Posts and Meta Information in CSV format
  26. Delete duplicated wp_postmeta record
  27. WordPress plugin to publish to multiple remote WordPress blogs
  28. Post publish only hook?
  29. Publish pending article from front end with a button?
  30. How to add metabox for post of specific category
  31. How to add a “publish” link to the quick actions
  32. How to limit user to publish post per day and per role?
  33. Will a large postmeta table slow a site down?
  34. Update all posts automatically when using post_meta
  35. upload image in a meta box
  36. When a user creates a post (pending), send a confirmation link that allows them to publish
  37. Change slug with custom field
  38. In what sequence are the hooks fired when a post is “published”?
  39. Restrict the Number of Posts an Author can Publish (over time)?
  40. Add javascript when post is published
  41. Better post meta efficiency?
  42. featuring old articles without messing up with the archive
  43. Setting post meta data to random value during post status transition / on publish
  44. meta_box or custom_field as a second tinymce post-instance?
  45. Edit meta data does’t work with custom sql
  46. 1 column admin screen options – move submitdiv to bottom
  47. Publish posts only after the condition is met
  48. multicheck box for post metabox
  49. Hiding by default specific post status on backend list?
  50. Create A Metabox For A Custom Field
  51. Human Time Diff, change mins to minutes
  52. Change post format using custom field
  53. Have save_post write to database image meta [closed]
  54. Detect Post Type when publish_post is ran
  55. Does WP get all post_meta on POST page?
  56. How can I display a specific user’s first published post?
  57. Does WordPress remove draft status automatically?
  58. Sanitizing `wp_editor();` Values for Database, Edit, and Display
  59. Prevent post from being published if no category selected
  60. Exporting Data from WordPress into a flat table
  61. Send email to user that his post has been rejected
  62. Adding Multiple Values to a Post Meta Key
  63. Limit number of posts a user can make per minute?
  64. Save list from a custom meta box?
  65. Using Custom Posts with Metaboxes and Drop-downs
  66. Every possible way to get data (posts) from WordPress
  67. publish_post conflicts with save_post
  68. PHP Notice error (when on 404 page)
  69. What Is meta_id In wp_postmeta?
  70. Notification to Admin or Author upon new post [duplicate]
  71. What differences are there between a Privately Published post and a Draft post?
  72. Checking if a post with certain meta value exists
  73. How to run a function when post is edited or updated using publish post action?
  74. How can I create custom button in post.php
  75. How to permanently delete a post meta entry?
  76. Add custom field automatically (add_post_meta) with value based on number of words of article
  77. Automatic value for custom fields for posts
  78. How to generate numbers indistinguishable for the IDs of the posts
  79. Modify WP_Post before processing
  80. Understanding and using metaboxes in posts
  81. Save re-arranged draggable post items to wordpress database
  82. I would like to give special promotion for the first 100 posts in my blog? Can anyone tell me how to do that?
  83. Change post_date to post_modified date on post template?
  84. count the total number of comments the user has received for his published posts
  85. Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
  86. Automatically Updating Publish Date Bug
  87. Dashboard :10 Last draft page and 10 last pending review page (metabox)
  88. How can I schedule a PAGE to go live at a future date/time?
  89. How to give capability (publish contributors posts) to author role?
  90. How can I sort posts by the date and a custom meta field?
  91. is there a way to show the the post title after the image?
  92. Get Meta Key Value While Saving Post
  93. Print a message if excerpt is empty after posts have been publish/update!
  94. Adding custom fields to bbpress reply form
  95. Check if checkbox is marked on publish/update post
  96. Force the “Choose from the most used tags” meta box section to always be expanded
  97. Decide user that can publish a post
  98. How to switch wordpress post status between publish and schedule in MySQL?
  99. Custom Posts Query and meta_query Sort Order
  100. Prevent scheduled post being published if date/time is past current date/time
Categories posts Tags metabox, post-meta, posts, publish
How can I add a row in a table from a Linux Shell?
Order of WP page load (including widgets, php, plugins, media, templates, and CSS) [duplicate]

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