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
- Update database from Quick Edit according to Checkbox state of Custom Post Type
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- Storing a many to many post type relationship in post meta and keeping SQL ability for Joins
- Dynamic Custom Fields
- Show Custom Post Type meta boxes only on Page Edit
- CPT Validation to not show “Post updated.”
- Custom filter function not working with Custom post type
- Filter Posts from the Main Query
- Importing Data from a Non-WordPress database, into WP
- Getting thumbnails of a custom posts featured images in a page-templates metabox
- save_post custom post type ? $_POST not working?
- List Taxonomies: Don’t list taxonomy if it has no post – depending on custom post-meta?
- Remove Post Custom Meta Box
- Can’t publish custom post type – “You are not allowed to edit this post.”
- Custom fields for custom post type
- Show future events based on custom field AND order by date
- Meta Data for Custom Post Type not saving
- Custom Post Meta from custom metaboxes is randomly being deleted
- Check if post with same meta value exists
- Filter date from post meta when date is in string format
- Create new custom post and post category of same name
- Get only used meta_values
- If Post Meta Equals Current Title Conditional Advanced Custom Fields
- Is there a way to exclude posts based on meta_values?
- Do posts, pages and / or custom post type objects have unique ID numbers or can there be multiple objects with the same IDs?
- Mutiple Select only POSTing 1 value
- Archieve.php not loading for custom post type
- Submitting Custom Post Types with custom fields from Front-end form
- Custom Post Type Metadata Not Saving
- detect when a custom post is cretaed for the first time
- Use remove_meta_box conditionally on custom post type
- create custom meta box with default value
- Get $post->ID from a URL
- Displaying a div from an assigned meta_value when on a page
- Meta data (Tags and Categories) for Custom Posts not showing.
- Display different information of a custom post type
- Include php on a specific page template
- Create Array from custom post type to display a slider
- Setting Post Title via Meta Data returns Auto-draft
- wp_trash_post action hook with custom post type
- How to Echo Metadata Value in Currency Format
- Issue on Working with Metabox – Checkbox to enable Sale Items
- Filter posts by tax (dropdown) and meta value
- How do I amend form data before it is saved for a custom post type
- delete_post_meta() for whole CPT / multiple posts?
- How to get specific post meta by title or id
- Publish and save specific postmeta to a filtered post_type
- Running a wordpress action when a custom post type term (taxonomy category) is changed
- How to move a post to different post type with all meta data?
- Why do I have to press the “Update” button twice to save my meta box values?
- How can I display a drop-down select of Post Names
- how to show records that don’t have custom meta value
- How check if a post is saved from backend or frontend?
- WP API Response does not show my registered metadata
- $post->post_meta not pulling any post in wordpress/php
- Values from meta-box not on $_POST
- WP_Query of custom post type sorted by meta_key has unexpected results
- Returning a custom content types with meta values
- Custom post type suddenly stoped working after WordPress 5 update
- Batch Extract Date from post title and put into ACF custom field
- Update post meta within save_post action
- copy images from custom field to another custom field
- How to show custom field on specific custom post type posts only when filled
- How to handle this specific case of custom post type?
- Save CTP post meta different values each day without overwriting previous values
- get_post_meta returns NULL in front-end, but correct result in back-end
- Cannot obtain custom meta information
- Problem with adding custom post type meta to header by plugin
- is_main_query() never called on WP 4.4
- How can I output WPAlchemy repeating fields meta values in my page template?
- Meta box data is saved but NOT displayed in the meta box text field. Why?
- How to call a post’s metadata in shortcode.php?
- Types plugin custom post add_action hooks
- Save Metabox Custom Field Value
- Echo custom post meta from options array
- Value of post meta dropdown is not showing in WordPress
- Meta box data not saving
- Get all metadata for a given custom post type
- WP_Meta_Query object with conditionals
- Trying to write shortcode with get_post_meta but isn’t working
- Loading plugin text domain before registering post type
- Related posts meta_query CPT
- Meta box with front-end styling
- Sanitaizing Select Optin For Custom Post Type Metabox in WP
- add_action ‘init’ from inside a class for custom post types
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- Advanced custom field – posted fields from custom post type