Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

update_post_meta() whenever custom post type is updated

You’re right to use ‘save_post’ action hook.

Try this:

<?php

add_action('save_post', 'some_function');

function some_function($post_id)
{
        if(get_post_type($post_id) != "VA_LISTING_PTYPE")
        return;
    $meta_value = get_post_meta( $post_id, 'featured-cat', true );
    if($meta_value != 1)
        return;
    update_post_meta($post_id, 'website', '');
    update_post_meta($post_id, 'twitter', '');
    update_post_meta($post_id, 'facebook', '');
}

if you’re on WordPress 3.7 or higher, you can use it this way:

add_action('save_post_VA_LISTING_PTYPE', 'some_function');

function some_function($post_id)
{
    $meta_value = get_post_meta( $post_id, 'featured-cat', true );
    if($meta_value != 1)
        return;
    update_post_meta($post_id, 'website', '');
    update_post_meta($post_id, 'twitter', '');
    update_post_meta($post_id, 'facebook', '');
}

I hope it work with you.

Related Posts:

  1. Custom post type save_post action not firing
  2. flush_rewrite_rules on save_post Does Not Work on First Post Save
  3. Trigger “unsaved changes” dialog for custom post meta changes
  4. Using preg_replace to filter custom textarea
  5. What do the numbers mean at the end of add_action(‘save_post’)…?
  6. How to detect that the save_post hook is calling the callback associated to the current edit post page only
  7. How can I get some of a posts meta data whilst it is still inserting?
  8. Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
  9. Custom post type meta fields missing on save_post_type
  10. How to save post_status using action save_post?
  11. Custom meta box data not saving
  12. Problem with ‘save_post’ hook not running
  13. Create action running on trashed_post hook to modify post_meta value
  14. Update database from Quick Edit according to Checkbox state of Custom Post Type
  15. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  16. Storing a many to many post type relationship in post meta and keeping SQL ability for Joins
  17. Dynamic Custom Fields
  18. Show Custom Post Type meta boxes only on Page Edit
  19. CPT Validation to not show “Post updated.”
  20. Custom filter function not working with Custom post type
  21. Filter Posts from the Main Query
  22. Importing Data from a Non-WordPress database, into WP
  23. Getting thumbnails of a custom posts featured images in a page-templates metabox
  24. save_post custom post type ? $_POST not working?
  25. List Taxonomies: Don’t list taxonomy if it has no post – depending on custom post-meta?
  26. Remove Post Custom Meta Box
  27. Can’t publish custom post type – “You are not allowed to edit this post.”
  28. Custom fields for custom post type
  29. Show future events based on custom field AND order by date
  30. Meta Data for Custom Post Type not saving
  31. Custom Post Meta from custom metaboxes is randomly being deleted
  32. Check if post with same meta value exists
  33. Filter date from post meta when date is in string format
  34. Create new custom post and post category of same name
  35. Get only used meta_values
  36. If Post Meta Equals Current Title Conditional Advanced Custom Fields
  37. Is there a way to exclude posts based on meta_values?
  38. Do posts, pages and / or custom post type objects have unique ID numbers or can there be multiple objects with the same IDs?
  39. Mutiple Select only POSTing 1 value
  40. Archieve.php not loading for custom post type
  41. Submitting Custom Post Types with custom fields from Front-end form
  42. Custom Post Type Metadata Not Saving
  43. detect when a custom post is cretaed for the first time
  44. Use remove_meta_box conditionally on custom post type
  45. create custom meta box with default value
  46. Get $post->ID from a URL
  47. Displaying a div from an assigned meta_value when on a page
  48. Meta data (Tags and Categories) for Custom Posts not showing.
  49. Display different information of a custom post type
  50. Include php on a specific page template
  51. Create Array from custom post type to display a slider
  52. Setting Post Title via Meta Data returns Auto-draft
  53. wp_trash_post action hook with custom post type
  54. How to Echo Metadata Value in Currency Format
  55. Issue on Working with Metabox – Checkbox to enable Sale Items
  56. Filter posts by tax (dropdown) and meta value
  57. How do I amend form data before it is saved for a custom post type
  58. delete_post_meta() for whole CPT / multiple posts?
  59. How to get specific post meta by title or id
  60. Publish and save specific postmeta to a filtered post_type
  61. Running a wordpress action when a custom post type term (taxonomy category) is changed
  62. How to move a post to different post type with all meta data?
  63. Why do I have to press the “Update” button twice to save my meta box values?
  64. How can I display a drop-down select of Post Names
  65. how to show records that don’t have custom meta value
  66. How check if a post is saved from backend or frontend?
  67. WP API Response does not show my registered metadata
  68. $post->post_meta not pulling any post in wordpress/php
  69. Values from meta-box not on $_POST
  70. WP_Query of custom post type sorted by meta_key has unexpected results
  71. Returning a custom content types with meta values
  72. Custom post type suddenly stoped working after WordPress 5 update
  73. Batch Extract Date from post title and put into ACF custom field
  74. Update post meta within save_post action
  75. copy images from custom field to another custom field
  76. How to show custom field on specific custom post type posts only when filled
  77. How to handle this specific case of custom post type?
  78. Save CTP post meta different values each day without overwriting previous values
  79. get_post_meta returns NULL in front-end, but correct result in back-end
  80. Cannot obtain custom meta information
  81. Problem with adding custom post type meta to header by plugin
  82. is_main_query() never called on WP 4.4
  83. How can I output WPAlchemy repeating fields meta values in my page template?
  84. Meta box data is saved but NOT displayed in the meta box text field. Why?
  85. How to call a post’s metadata in shortcode.php?
  86. Types plugin custom post add_action hooks
  87. Save Metabox Custom Field Value
  88. Echo custom post meta from options array
  89. Value of post meta dropdown is not showing in WordPress
  90. Meta box data not saving
  91. Get all metadata for a given custom post type
  92. WP_Meta_Query object with conditionals
  93. Trying to write shortcode with get_post_meta but isn’t working
  94. Loading plugin text domain before registering post type
  95. Related posts meta_query CPT
  96. Meta box with front-end styling
  97. Sanitaizing Select Optin For Custom Post Type Metabox in WP
  98. add_action ‘init’ from inside a class for custom post types
  99. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  100. Advanced custom field – posted fields from custom post type
Categories custom-post-types Tags actions, custom-post-types, post-meta, save-post
TinyMCE Keyup Function
Using wp_filesystem in Plugins to store customizer settings

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress