The call to get_the_ID()
possibly worked by happy coincidence of there being an available post object to pull the ID from. However, realistically you should have been looking at data available to the filter for this ID instead, here’s how.
First update you add_filter
declaration to bring in the second variable from wp_insert_post_data
.
add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 2 );
Then update your callback(function) to receive that additional data.
function modify_post_title( $data, $postarr ){
And update your ID variable with the value from $postarr
.
$id = $postarr['ID'];
Hope that helps.
Related Posts:
- How to change the case of all post titles to “Title Case”
- Show the content that is after the excerpt using child theme
- Related Posts: Changing Function For Posts Per Page
- Get post title by Alphabet
- display last post modified date in genesis child themes
- How Do I Get My Post Tags to Alphabetize?
- Add title for previous and next posts to Yoko Theme
- Images inside post title
- Loop doesn’t show title of second post and posts thereafter
- How To capitalize The First Letter Of Every Word In The Post Title
- Change all author links in Blog roll
- disable Tab post on nav-menus page (Admin)
- Adding bootstrap classes to video shortcodes
- How to show show the Second page title in the page
- Every second post different class in blog view
- Format latest/newest post differently
- How to get links to the last N posts in a specific category?
- is_page Funtion for Posts ?
- Create a list of posts with topic headdings
- Post type no single page
- Get post meta retrieving wrong value
- Adding a user’s ID behind the tag ref link address
- Blog post not showing title
- The_excerpt() doesn’t parse – how to change that?
- How can I remove the first two words and shorten get_the_title()
- How to only publish posts with image in it
- How do I include the category next to the title of a post?
- Isn’t the way posts are displayed very unefficient?
- Add custom text automatically on each post
- How to check in functions.php if there is data in a WP_Query?
- How to style archive post titles… but only those posts who have comments?
- Replace image name on upload to the new post name on front-end form
- Edit the post title from the frontend
- restrict incrementation of post vies count when refreshing the page
- Why in my query is display two title?
- Defined function isn’t showed on page
- WordPress 302 Redirect to Random Product/Post/Page
- Image behind the post’s title
- singular posts using archive styling
- Change Post Title For Specific Category
- Getting Whitescreen when publishing a post [closed]
- Using system date format
- Get post by tag
- Add code to a specific post’s content
- Related Posts function not working
- the_content() Not Grabbing All Content
- How to remove “» (title of post or page)”?
- Un-highlight Blog Menu Item when Category Menu Item is Selected
- Is it advisable to use $post->comment_count instead of get_comments_number( $post_id )
- Auto update post title and slug when post status is changed
- Get featured image on hover of post title [closed]
- Query function not executed between element [closed]
- Microformats in a single post – layout conflict
- Optimize CPT-function with a loop
- How do I display the post_title with get_permalink?
- saving/reading custom field value does not work – no value gets POSTed
- Post titles and thumbnails as links to custom post types?
- Same post appears in related Posts?
- Internal linking to posts permalink fail because of spaces and stripe at postname
- If post exists, make it a comment in existing post with same name?
- Have h2 tag not show up if there are no blog posts
- WordPress as CMS: How to manage/handle images assigned to a post as full-sized background images in a slideshow?
- Making a wordpress page print friendly
- Help on conditional statement to accompany wp_insert_post function please?
- How to implement a WordPress comments function?
- How to add content above footer in posts from specific category
- Changing The Default Header POST Title and Description text by category in wordpress
- Change modified date to current date when title updated automatically
- Set Default Post as Parent Child (Nested) Relation
- How to select a category automatically based on a word in WordPress post title?
- I need to create “View Profile” and “Edit Profile” links by incorporating the Post Title/ID, but can’t seem to manage it
- how to show current date on post title which should be auto update in every day
- Adding Text after Post Title based on Category using IF Condition – But not for menu items
- how to show comments only author which send own posts in wordpress
- How to merge the content of posts that have the same title?
- get category in list of posts // shortcode for custom related posts
- shortcode // get posts by ids
- How to put the author of the post in the comments?
- Check if almost 10 year old – working code is up to date
- Alt text attributes not showing over portfolio images
- Find most used words in post titles
- WordPress Sticky Post Count “Fix” Breaking Pagecount by 72 pages!
- $post->post_content empty while all other properties are correct
- Function is printing twice – any suggestions?
- Adding an option to post editor to show a site disclaimer or message
- How to add a custom class attribute into code wrapper? [duplicate]
- Post title not displaying as recorded in the wp_posts table
- Remove pagination if search returns empty
- Remove HTML tags from all posts
- Set a post expiration and delete a post when expirate
- Create/Set Category as Title of Post
- long-title posts do not want published
- Please I want to prefix my WP posts title according to each category
- I want to change the WordPress comments file
- Add id attribute to h1 element of wordpress post
- Replace Tag Keyword With Link Within Post Content
- Excluding tag Link from html tags in Post content
- Save All Post Permalink From A Specific Category into a .txt file
- Post title spoiler how?
- Odd hyphen added at end of blog post