It’s just a guess, since I haven’t tested your code, but… There is a part that looks pretty sketchy for me:
All your actions are run only if this condition is true:
if(isset($post_type) && $post_type == "listings"){
And where that $post_type
variable comes from?
$post_type = get_post_type();
So you don’t pass any post_id to that function call… This means that you work with global $post object. But there is no guarantee that such posts exists.
There is a reason why save_post
hook passes post_id as param – you should use it inside your function…
So changing the line above to:
$post_type = get_post_type($post_id);
should solve your problem.
PS. There’s no point in doing that:
$post_types = get_post_types();
unset($post_types['listings']);
You don’t even use that variable in your code later on…
PPS. save_post
is an action, so you don’t have to return anything in it.
Related Posts:
- what is correct way to hook when update post
- Enforcing password complexity
- Does an activated plugin automatically mean its methods are available to other WP functions?
- How to set custom cookies before output
- Check php version before theme activation
- Getting the action’s tag name within the action
- How can I remove “Proudly powered by WordPress” from twentyeleven without modifying footer.php?
- Why is my custom meta box input not saving
- Can i check if user is doing any ajax request?
- add_meta_boxes action with refresh on save
- Save selected item from dropdown menu in a meta box as a metadata value for a custom post type
- How can i create a function to get youtube video time
- Second select list values are not saved after clicking update
- Use wc_enqueue_js only on specific pages – nested add_action
- How to Remove a Filter from the Admin List Table?
- Update Custom Field on Imported Post Creation
- Set Primary category using the Yoast SEO plugin
- Insert post without actions/hooks
- Find variables available at a given hook
- Why do filters/actions require an argument count?
- Appending meta value onto post content in WordPress during save_post
- save_post vs post_updated
- Executing `createimagefrompng()` from save_post hook (or equivalent hook)
- Delete option value from array using update_option()
- How to access function from outside of a class within this class in WP plugin?
- Extend a class of a plugin
- action hook wp_head higher priority as all other plugins/hooks
- How to use return in my custom function instead of echo
- WP_cron won’t trigger my action
- Adding Default Settings to Theme My Login plugin
- action is not called after a php request
- Remove an action hook within a Class
- Ajax not working es expected (Returns 0)
- How to pass arguments to add_action() or retrieve return value of called function?
- Custom Form Processing Issue
- add_action shortcut?
- Is it acceptable to treat a filter like an action?
- add element with add_action to posts from a specific category ID
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Trying to place a custom field after the total section in the checkout page in woocommerce
- Set meta field to publish date + 2 weeks
- Adding widgets to my plugin page instead of WordPress dashboard
- action theme mailchimp subscriber fields
- Adding function to Genesis genesis_header [closed]
- Modify custom field input data before creating a new post
- Error call_user_func_array() expects parameter 1 to be a valid callback when using image_size_names_choose
- jQuery code not working when included in functions.php
- add_action taking an array with the 2nd argument?
- Should `wp_login` be used since it’s deprecated?
- How to show a users bio on a page
- Override a function defined in wp-includes/comment-template.php
- Nested “do” and “add” Actions is possible?
- Change order of custom submenu link in WP Admin?
- How to catch wordpress post ID when it’s published
- WordPress redirect redirecting too many times or not at all
- Can not add admin notices from the edit_user_profile_update hook (notices not being displayed)?
- How to pass argument to add_action while the method is inside a class?
- Display attribute on shop page after the title
- Action Hook Inside WordPress Plugin Shortcode
- update_post_meta() not saving data inside of save-post filter
- Woocommerce custom Plugin in wordpress [closed]
- Class property seems to lose scope, attached to save_post action?
- How to pass hook variable to function?
- save_post action inside a custom metabox class not working
- Change image data durgin upload
- How to check post meta isset or not empty during publish/save post?
- save_post trigerred twice
- WordPress Post Block Element not properly parsed with the_content filter
- Remove an action created by a Gravity Forms add-on
- remove_action from parent theme using child theme functions.php
- Use PHP Class in WordPress functions
- WordPress How do I pass a variable from one add_action to another?
- I want to hide “sold by” on certain pages with id page 43
- Get original value in save_post action hooka
- How do I remove an action hook inside a class that is called by another class?
- add_action in wp_head accessible from class
- Hook into all password resets in WordPress and get password before hashing?
- Why should I need to add init action to include PHP file to WordPress Plugin?
- remove_action() not working in page template – Genesis
- Unable to pass arguments to function used in add_action
- How to hook into the subscriber /wp-admin/index.php page?
- Add two or multiple functions in WordPress Post or Page
- Submit to itself don’t work
- WordPress HTML Helper
- At what point during a typical request does the $wpdb object become available?
- Save data of select list after clicking save
- How does add_action ‘comment_post’ work?
- Highlight posts currently being edited on multiple editor site?
- Custom action on comment post
- WordPress Plugin Receive a Link
- How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?
- How to add custom checkout field in user details mail template
- Cannot modify header information – headers already sent
- Fix incorrect related posts code snippet
- Why a class property becomes empty?
- How to change wp-admin and wp-login urls
- How to sort custom sortable column by custom table value
- How can I change the location where the custom field is displayed in the Quick Edit tab in WordPress
- Save_Post change Custom Post Type Post title to post id number
- Is there a hook that I can use when a fatal error occurs?