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
- Function to execute when a post is moved to trash .
- Set Post Title to Read-only and Disable Permalink Slug Editor in Gutenberg
- Fatal error: Call to undefined function post_exists()
- Code to auto expire posts after 30 days
- Keep a fluid max number of posts on site
- Custom colors for post rows based on post meta value
- How to add an admin function only to posts, not pages?
- Custom wp_trim_words() function not trimming right
- Delete Post From Front-End and attachment permanently
- Limit function to specific post category
- Testing for post title in ‘if/else’ statement returns no content
- When paginating a Page with the tag, how can the 2nd and subsequent page styles be customised?
- get_post_field – Title without paragraph
- Function to show random posts from a category
- Add Category name to Post Title (h1)
- Hiding posts in a list from specified categories
- Sorting posts alphabetical that have single digits
- Checking is user author of number of posts?
- Create cron job without a plugin?
- How to rename “Publish” metabox title in post screen
- How to display following posts titles in separate div’s on a separate webpage
- Blog Posts not showing title
- Uppercase first sentence in every post
- Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
- How to Orderby Comments by post title?
- WordPress not opening posts with only numbers if permalink is post_name
- Force the “Choose from the most used tags” meta box section to always be expanded
- How to allow users to post only in certain category and hide elements from edit page?
- sql select for post_title and a term name
- WordPress is replacing double minus signs in Post Title, how to disable it?
- Order posts alphabetically: how to set order=asc in mysql query?
- Images inside post title
- Loop doesn’t show title of second post and posts thereafter
- How to show show the Second page title in the page
- Post type no single page
- Adding a user’s ID behind the tag ref link address
- Blog post not showing title
- How can I remove the first two words and shorten get_the_title()
- How to check in functions.php if there is data in a WP_Query?
- Edit the post title from the frontend
- restrict incrementation of post vies count when refreshing the page
- Defined function isn’t showed on page
- WordPress 302 Redirect to Random Product/Post/Page
- Image behind the post’s title
- Add code to a specific post’s content
- the_content() Not Grabbing All Content
- How to remove “» (title of post or page)”?
- 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?
- 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
- Making a wordpress page print friendly
- Change modified date to current date when title updated automatically
- 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 merge the content of posts that have the same title?
- How to put the author of the post in the comments?
- Check if almost 10 year old – working code is up to date
- WordPress Sticky Post Count “Fix” Breaking Pagecount by 72 pages!
- Function is printing twice – any suggestions?
- 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
- Create/Set Category as Title of Post
- Add id attribute to h1 element of wordpress post
- Save All Post Permalink From A Specific Category into a .txt file
- Odd hyphen added at end of blog post
- How to Display Most View Post in the template file?
- 2 Domains, Same Content, Different Titles?
- Post Category link is same with Page link
- Show post excerpt
- How do I apply a wordpress function to something with no ID inside an archive page?
- Show all posts from the tags without having to set all of them
- Show author bio box
- Display author bio box
- Call image from post on index page?
- How to edit label_submit styling?
- How do I get thumbnails?
- How to limit the number of results for all query_posts on mysite
- Get post title of faulty link on 404 error page
- User driven content problems
- Is it possible to have different header style blog titles in different categories?
- Custom Post Title as search term
- Is there a way to separate wordpress titles from their posts?
- Notify Author of the post if admin deletes his post and perform some function
- How do we display a certain category type on a page while hiding all others?
- How remove “recent comments” title without modifying code? [closed]
- Show Next/Previous without Link
- How to change Post title background size?
- Filters do not work when there are multiple (one works)