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 to create content automatically when a post is published?

You can use the transition_post_status action to manipulate the post content at the time when it is published. You just need to add a function like the one below into your theme or plugin:

function post_published( $new_status, $old_status, $post ) {
    if ( $new_status == 'publish' && $old_status != $new_status) {
        //Do whatever you want to the post
    }
}
add_action( 'transition_post_status', 'post_published', 10, 3 );

In this function, $post is a WP_POST object, so you can use it to manipulate the post in all kinds of ways. Adding a string to the top of the content would be a simple as this:

$newcontent="the content you generated";
$post->post_content = $newcontent . $post->post_content;

I am not sure what you want DISPLAY OF CONTENT to be. If you just want to display the post meta in some original way, then just editing your template file would be much simpler.

Check out these Codex pages for more info:

WP_Post

Post Status Transitions

Related Posts:

  1. How to Make infinite loop of post
  2. Get_post_custom not fetching value from array wordpress
  3. How to get post content by calling ajax?
  4. Get the ID of the latest post
  5. Retrieving 3 latest post from each of 5 different custom post types
  6. Grossly inefficient wordpress loops!
  7. Newer/Older posts links display same posts on every page
  8. How do I write this SQL statement for Posts written in last 24 hours?
  9. How to show related posts by category or custom post type?
  10. How to create posts (not post template) to be displayed on projects page?
  11. IF statement in a do_shortcode
  12. Quickest way to get last or oldest post date – WP Query
  13. Displaying custom posts only if custom meta box’s date is not expired
  14. Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
  15. get_template_part for custom post type content not working
  16. Loop on front-page.php
  17. get_template_part() – post-meta not working?
  18. How to get all posts except for one post from a certain custom post type?
  19. Create a random unique 6 digit number as custom field for custom post type
  20. WordPress Orderby Numeric Value Not Working
  21. Shortcode for display posts on home page show only one post
  22. How i can add ‘N’ page of ‘N’ pages under posts loop?
  23. Show the same Article Available in Other Categories
  24. Meta Key Value in current-user-only loop
  25. I would like to have different styles for my posts based on the content of each post
  26. List custom taxonomy specific to one custom post type
  27. Post image in WordPress not appearing on home page
  28. Update Post Meta for a logged in user
  29. Two Custom Post Types Many to Many Relationship
  30. Update postmeta Parent when post_status child change
  31. Shortcode not working with post counter
  32. Conditional for a Single Post That Belongs to a Category?
  33. Reworking function for counting custom post type posts count
  34. Get only used meta_values
  35. Create Array from custom post type to display a slider
  36. WP_Query with custom post type ID
  37. Displaying multiple post types on home page
  38. Batch Extract Date from post title and put into ACF custom field
  39. display posts of custom post type with custom taxonomy
  40. Get post format
  41. Custom wordpress loop
  42. displaying content of custom post type
  43. Posts are not rendering perfectly [closed]
  44. Display post from custom post type
  45. Use post in multiple places on a page with multiple posts
  46. The loop does not show users
  47. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  48. How to fetch posts that are stored in the different table than (default) wp_posts?
  49. If/Else child list for Custom Post Type single template within loop?
  50. Add a form in every post and save data in post meta
  51. SELECT custom post type and its meta in SQL
  52. Save data is post using php front end
  53. Limiting the Number of User Posts to Their Own Posts
  54. Show posts from WP Custom Post Type selected from a field in a metabox
  55. SEARCH QUERIES – REVERSE OUTPUT
  56. Custom meta fields not showing up in WP_Response Object via custom endpoint
  57. How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
  58. How can I group by Taxonomy on Custom Post Type while filtering out based on custom Meta
  59. subtracting the current post form then whole loop, which is generating all CPT titles
  60. Display title of all custom posts from same taxonomy term on a custom post template
  61. Custom post Query and WordPress Post Query Clash
  62. update a posts of other custom post type
  63. Get post from Category by Priority
  64. Only show current category post
  65. get_post_meta for Custom Post Type ( CPT )
  66. How To Loop Through list with Custom Post Types
  67. Popup panel is only displaying 1 entry ignoring all others
  68. Edit post meta direct from post.php?
  69. Display a post count from a custom metabox selection
  70. Turn post into simple slideshow
  71. Custom Post Type children and grand-children in one list
  72. Pulling in a particular post into a single page based on the post id passed into the code
  73. Top 30 Songs using Custom Post Type
  74. Styling first post using Advanced Custom Fields
  75. How do I display the index position of a post from a custom post type?
  76. why get_post_meta is returning 0?
  77. the_content() stop images being pulled through
  78. How do I correctly query posts from a post ID?
  79. Custom Post Type meta value is being saved in array, instead of just the string (as value)
  80. Display posts from another page on home page in wp-editor
  81. Automatically add custom taxonomy when meta value gets to a set number or beyond
  82. show custom post’s post in two different divs [duplicate]
  83. How to get permalink of post based on post name?
  84. I am having a problem with fetching product data in the Gutenberg block editor
  85. Default post showing more than intended
  86. button onclick with get_post_permalink
  87. How to add new post using a form to categories when categories are using as menu
  88. How to set the mainpage of a custom post type?
  89. Assign a template to a custom post type when displayed by the main loop on the home page
  90. Custom Post type content within a slider
  91. Different post title, keywords and description
  92. Trying to add a class to post links
  93. posts within custom post type all share the same content in the front-end
  94. Custom Post Type and Taxonomy Loop Output Is Wrong
  95. Save CTP post meta different values each day without overwriting previous values
  96. How to Query in WordPress which shows Alphabetic Posts?
  97. get_post_meta returns NULL in front-end, but correct result in back-end
  98. Post Query not working
  99. how to get options to choose post format in add new post
  100. postsperpage value not being applied
Categories custom-post-types Tags custom-post-types, get-posts, loop, post-meta, posts
Redirect A URL Pattern In WordPress Using .htaccess
Put folder in theme via plugin

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