I did not work it out using save_post or any other save-filter, so as I am only needing to do the same for the title, I used the default_title
filter. This means that it works for drafts as well.
add_filter( 'default_title', 'change_title', 10, 2 );
function change_title( $title, $post ) {
return 'PO' . $post->ID;
}
Notice that here I am using the newly created post’s ID, so I don’t have to fetch $last_post_id as you do, and perhaps you don’t have to do that either if you do it like this. Remember to check the post type before changing the title though.
I have not tested to do the same with the slug, but I noticed there is a similar filter for the slug, called wp_unique_post_slug
. Hopefully this will help you. 🙂
Edit: here is the filter from WP Core code, https://developer.wordpress.org/reference/functions/wp_unique_post_slug/
Related Posts:
- Get post ID from wp_insert_post()
- WP insert post and custom taxonomy
- How do I programmatically add items of content to a custom post type?
- Not Able to Insert Taxonomy Term Using wp_insert_post()
- How I upload, save and set a featured image from my frontend?
- Trying to save custom post type from frontend partially working
- wp_insert_post custom taxonomy
- Assign category to front end post
- How can I programmatically save data into custom fields that contain serialized data?
- What hook should be used to programmatically create a post only when master post is updated?
- WordPress tax_input only if logged in
- Programmatically adding posts
- Is it possible to create a post using a metabox?
- How Can I Set the Post Author of a Post I Just Created With PHP?
- Auto-generated posts not showing in backend (but being counted!)
- wp_insert_post generates endless posts
- create parent post using wp_insert_post
- Cron job for creating posts not excecuting properly
- How to checked selected category checkbox when my custom post inserted from frontend
- Post author for revision not being set on update/insert
- Add CPT values to Database
- Why cant I add a custom post type to a custom taxonomy?
- wp_insert_post wrong post type [closed]
- Programatically inserted posts not showing in Posts Table
- Is it possible to add posts and images (auto resize) for custom post types with a script?
- Update post if exist from PHP
- WordPress hook which triggers on post import
- How to handle new post from API request?
- How to handle this specific case of custom post type?
- insert image with custom post type
- importing table data to custom post type
- How can I get some of a posts meta data whilst it is still inserting?
- See if the email exists or not
- WP_Insert_Post creating duplicate posts when logged in
- wp_insert_post from XML feed only inserting first post
- What is the correct way that when creating a custom post type assign values to custom fields created with pods framework?
- How do I find out which (page) template file my custom child post is looking for?
- wp_insert_post deleting previous post custom meta
- Published page but it is page not found
- How to insert post 6 times after user register like ask.fm
- wp_insert_post() creates duplicates with ‘post_status’ => ‘publish’
- automatic creation of custom post type articles
- Submitting custom post from frontend,jQuery ajax, and custom validation – can’t find proper place to insert wp_insert_post()
- UPDATED: Save a custom_field value when automatically creating a post using wp_insert_post
- Generate slug and meta data if meta field is empty
- Add a image to a post published on a CPT from the front-end
- wordpress form processing to custom post type not working
- install.php Custom Taxonomy Term not being added to custom post
- Omitted Content After Post-Publish Insertion
- Is this the correct way to add post-slug input field?
- wp_insert_post not working for custom post type?
- After wp_insert_post() custom post type does not show in the admin
- Using wp_insert_post to create custom posts with ACF image field
- Add a post when another post type is inserting
- How to add a post page from a button without reloading
- Displaying multiple post types on home page
- Category Icon on custom post type
- Prevent custom post type from showing up in custom menus
- How to do admin CRUD & Pagination
- looping though custom post types and only return results in a given taxonomy
- display custom taxonomies limited to custom post type?
- Allow front end users to add data to a custom post type
- custom fields cannt be seen with version 3.1
- Displaying custom post types as a gallery
- Get_the_terms restrict output
- Populate a custom field dropdown with post titles by author
- Can I query posts by taxonomy conditionally based on post type?
- Shortcode leaves no space for other elements?
- Can anyone clarify difference between archive-{posttype}.php, type-{posttype} and date.php?
- Conflict between wp_list_pages and get_posts – list pages not displaying
- User-submitted reviews of different custom post types
- How to make a pulldown menu display custom meta terms in a theme?
- After creating custom post type, URL to custom posts are invalid
- Custom post type index (maybe using get_template_part)
- Custom post type menu
- Listing all slugs?
- How can I merge this function(s) that inserts terms to a custom taxonomy with this other that adds a custom taxonomy filter?
- What would be a proper name for a custom post type created for static content?
- How to include category name/id in wp_query for retrieving “custom post type” from a particular category?
- Custom fields not saving in newest WordPress 3.0.1
- How can I display a drop-down select of Post Names
- Which file/template is in charge of taxonomies for custom post types?
- Implementing Pillar Posts; Long Posts yet with Some Page-Like Handling?
- get_post_types – exclude multiple post types by name
- Address as a content type post
- CPT Columns doesn’t show categories
- Custom post type loop with custom category filtering
- Hide Status Option From WordPress Publish Metabox and Rename Published on:
- Check if user has comment on current post
- How to conditionally add Custom Post Type to Front Page
- Role capabilities issue
- Assigning a category to a custom post type in WordPress
- Insert Custom Post Types
- How to inherit field value from parent post into in child / sub post
- Create field of Custom Post Types
- Dynamically insert code to custom post type loop
- how to show records that don’t have custom meta value
- How can I add a shortcode to query Custom Post Type with ACF in WordPress?
- Custom Post Types not queried in Custom Taxonomy archives or Native archives
- Show current custom taxonomy