Your original function relies on the $_POST['post_type']
being set to the appropriate value. As a general rule, you should avoid using global variables – if you use only want the function gives to you, you don’t have to think about the contexts in what it should be called.
In this case, that’s what’s happened. You’re function relies on a global variable $_POST['post_type']
, and while that works in one ‘state’ (publishing a post) it doesn’t in another (a cron job, updating a post). In short, $_POST['post_type']
isn’t always what you think it should be.
The following retrieves the post type from the passed $post
variable:
function intercept_all_status_changes( $new_status, $old_status, $post ) {
if ( $new_status == 'publish' && get_post_type( $post ) == 'tweet' ) {
// Post status changed
twitter_run_when_published ();
}
}
add_action( 'transition_post_status', 'intercept_all_status_changes', 10, 3 );
Related Posts:
- How come Featured Image isn’t showing up in my Custom Post Type?
- Redeclare/Change Slug of a Plugin’s Custom Post Type
- How to use a custom post type archive as front page?
- How to change default position of WP meta boxes?
- Displaying Custom Post Types In “At A Glance” Meta Box
- How to add specific terms in a custom post type?
- Assigning categories to custom post types via a front-end form; only works for native post type
- how to display author name in custom post type
- Default excerpt for parent of a custom post type
- Custom attachment function not working in v5.4.2?
- Limit custom post type to the authors only on front-end!
- Cannot display the_content() after removed WordPress 5’s auto embed feature (iframe & blockquote)
- Update main post with same category when creating custom post to update the modified date
- Urgent – WordPress keeps creating posts
- CPT tags not showing when editing post
- Move to trash custom post type post after ACF Date Picker date is older than today
- Attend event form with ajax
- From CPT Custom Loop into Shortcode?
- Create posts inside CPT post
- Persist meta box choices throughout all posts of same post type
- ACF field check value of field on all other articles
- How to get current post type?
- How to convert Post Object Custom Field into Tags
- Problem with multi checkboxes value in metabox?
- Load custom post type with ID in a shortcode
- Why is wp_list_authors not picking up Authors from CPT’s?
- Change Search display for Custom Post Type
- Create dynamic logo carousel without using any plugin
- Send mail to author when custom post type is saved
- subtracting the current post form then whole loop, which is generating all CPT titles
- Custom Function to redirect singular post if specific meta field is empty
- Recovering data about custom post and taxonomy types
- How to assign post to category
- fusion builder missing from custom post editor
- Using get_post_type with a custom URL format?
- Stored meta from attachment, video length?
- If thumbnail image else post title
- wordpress does not see the correct custom taxonomy hierarchy
- is using “require_once” in wordpress theme affect the speed ???
- $_SESSION Not working after X amount of page views
- Function for when new custom post type is created should do something
- Duplicate posts in my custom loop
- When post is Published, insert into custom table a number – custom post type
- Different Configuration for the_excerpt()
- WordPress page not showing up – replaced with last 10 posts?
- Custom permalink rewrite rules – how do I fix this?
- Post that populates itself (almost) automatically using data from imported excel file
- How to mark posts as visited
- Populate custom post type/custom fields from an external database
- How to sort custom post’s category by id from the theme’s function.php?
- Work and Display a Custom Post Type as a normal Post
- Custom Field to post_title
- Post Custom & Taxonomy 404 error
- Getting a 404 on single custom post type page when using rewrite on a custom taxonomy
- How To Display Category list from Portfolio post type plugin?
- Featured image in custom post is being disabled
- custom post type does not working when adding in child theme function
- Create 2-layered dropdown menus for custom taxonomy and custom post type
- can’t see categories in appearance-menu-categories
- call_user_func_array() error after moving to another server
- WP_Query function for custom post type
- Modify shortcode to work with custom taxonomies and slugs
- Calling the first & last post by category in custom post type
- Pagination fault in custom post type archive page [duplicate]
- How can i call a custom method on submission of a custom plugin post type?
- Set the Title of a Custom Post Type by code as Author’s Username
- Query custom post type and showing its content
- Function not pulling image or text from custom post type
- send email to all registered users when post expires
- Rich Custom Field for Custom Post type not saving
- Updating User Meta from Custom Post Field Upon Publish Not Working
- I want to split this into two functions
- Can’t preview custom post – Redirected to home page
- Generate daily archive whenever any post type is added
- Custom Loop for custom post type. Compare by meta_value?
- Invalid Taxonomy in template
- Allow authors to create article image
- Post AND page parameter for WP function
- Code in custom widget queries all posts, when it should only query the current post
- Custom post type functions.php if statement on action
- Add HTML before a specific div?
- How to string lines from the_content() hook in WordPress?
- Passing postid of Testimonial Custom Post in Shortcode Parameter
- Comments are not working on Custom Post Type
- Custom Post Types using wrong template (index) instead of archive-{type}.php – previously worked as expected
- How to I add count of custom posts listed in a post as a prefix to its title
- How to make a non-public post on wordpress approval?
- how to display custom taxonomies in front page
- add_rewrite_rule not working with custom post type
- wordpress category form fields in popup
- How do loop categories post from according in WordPress? is it impossible to solve this problem?
- Where paramaters of a custom function are coming from inside the loop?
- I want to show a list of posts under specified categories
- I want to show a list of post with title that have link goes to that post and icon under the specific category to which it belongs
- How to use wp_set_object_terms depending on page ID?
- Is it possible to use a post name in a custom post slug?
- How to display *block number* instead *date value* on WordPress posts?
- How to get the proper category in permalink with custom post type assigned to multiple categories
- Get current post type within functions.php
- Auto Generate Post Title from 2 ACF Taxonomies [closed]