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:
- Custom post type save_post action not firing
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- Trigger “unsaved changes” dialog for custom post meta changes
- Using preg_replace to filter custom textarea
- What do the numbers mean at the end of add_action(‘save_post’)…?
- How to detect that the save_post hook is calling the callback associated to the current edit post page only
- How can I get some of a posts meta data whilst it is still inserting?
- Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
- Custom post type meta fields missing on save_post_type
- How to save post_status using action save_post?
- Custom meta box data not saving
- Problem with ‘save_post’ hook not running
- Create action running on trashed_post hook to modify post_meta value
- Advanced search form with filters for custom taxonomies and custom fields
- Meta query with boolean true/false value
- Custom field values deleted when trashing custom post type
- How to get all custom fields of any post type
- Update CPT meta data using REST API
- How to change “Draft” string for status of custom post type to “Unavailable”?
- How do I remove all the metaboxes for a custom post type?
- Custom Queries: Joining On Meta Values From Two Custom Post Types
- Gutenberg how to make attribute to save to meta
- Get all posts from custom post type and insert in select input as metabox
- WordPress Admin Panel search posts with custom post meta values along with title
- How to Update post status using meta data in Custom post TYpe
- Rest Api v2 orderby meta_key in custom post type
- bulk Update post_meta with default values
- WordPress custom post action hook
- Unable to save or update postmeta for custom post type via action using save_post hook
- Using pre_get_posts to Filter Posts
- Remove “Get Shortlink” button in admin of custom post type
- Conditionally Query Custom Post Types by Post Meta for Blog Home Page?
- Add Post Url to Manage Edit Screen
- How can I display my custom metaboxes on a custom post template?
- Display all custom post type posts and order them by an optional meta_key
- need advice on how to do a lists using custom post types – taxonomy vs postmeta
- how to interconnect custom post types?
- Custom Post Status Transition Issues With Get Post Meta
- orderby in custom WP Query does not work
- Show the same Article Available in Other Categories
- How to get updated data when save_post triggers?
- How to set YouTube video as featured image?
- Notice: Undefined index: error and understanding wordpress
- Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
- Displaying custom taxonomy in the admin list of a custom post type
- Widget: Custom Post Type Post Listing Dropdown on Admin Side
- Can taxonomies of custom post types be used with category actions?
- How do I create an archive page as a including metadata?
- Custom Taxonomy terms aren’t getting referenced or saved in Quick Edit or Bulk Edit, only on Single product page?
- How to duplicate entire custom post type
- Two Custom Post Types Many to Many Relationship
- get_post_meta not working on publishing
- Troubles with acf/save_post and WP_Query
- Update postmeta Parent when post_status child change
- WordPress request fiter order by related post’s post_title
- Update database from Quick Edit according to Checkbox state of Custom Post Type
- Dynamic Custom Fields
- Remove Post Custom Meta Box
- Custom Post Meta from custom metaboxes is randomly being deleted
- Check if post with same meta value exists
- Do posts, pages and / or custom post type objects have unique ID numbers or can there be multiple objects with the same IDs?
- Archieve.php not loading for custom post type
- Meta data (Tags and Categories) for Custom Posts not showing.
- Display different information of a custom post type
- Create Array from custom post type to display a slider
- How to get specific post meta by title or id
- Running a wordpress action when a custom post type term (taxonomy category) is changed
- How can I display a drop-down select of Post Names
- How check if a post is saved from backend or frontend?
- $post->post_meta not pulling any post in wordpress/php
- WP_Query of custom post type sorted by meta_key has unexpected results
- Cannot obtain custom meta information
- Save Metabox Custom Field Value
- delete duplicate meta_value with same post_id
- Search CPT Title AND Meta
- Empty meta-box returns publishdate if no value is set?
- Custom Post Type Meta Box Text Input Field Won’t Save When Blank
- Filter search posts by post meta?
- Custom Meta Box with variable number of fields
- Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
- Attaching more than 1 parent (Post) to a media file
- How to return/export only data showing on screen in custom post type view all screen
- Use WP_query to match post types based on custom field values
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- publish_post action callback not executed, why?
- How to get post by meta value
- Get meta values from parent post and save in child post
- How do I get all authors posts of a custom post type outside loop
- How to store additional data that is related to core data
- Stored meta from attachment, video length?
- Order posts by meta value hiding posts instead of re-ordering
- save_post affect creation and deletion
- custom search results – order results differently by post type
- get_post_meta for Custom Post Type ( CPT )
- Complex strcuture as CPT or taxonomy for use in woocommerce product variations [closed]
- Function that get ACF fields value before saving
- Add auto increment value to custom meta
- Retrieve post data via WPDB class
- Random meta field from specific custom post type
- Custom Form Data save after Login User