Maybe you can move all the logic to added_post_meta
& 'updated_postmeta'
hooks.
add_action( 'added_post_meta', 'update_carnews_adverts_aprent', 10, 4 );
add_action( 'updated_postmeta', 'update_carnews_adverts_aprent', 10, 4 );
function( $meta_id, $object_id, $meta_key, $meta_value ) {
if ( $meta_key !== '_wpcf_belongs_carnews_id' || ! is_numeric($meta_value) ) return;
$post = get_post( $object_id );
if ( $post instanceof WP_Post && $post->post_type == 'carnews-adverts' ) {
$parent = get_post( $meta_value );
if ($post->post_title !== $parent->post_title || $post->post_name !== $parent->post_name) {
$post_update = array(
'ID' => $post->ID,
'post_title' => $parent->post_title,
'post_name' => $parent->post_name
);
wp_update_post( $post_update );
}
}
}
Related Posts:
- What hook should be used to programmatically create a post only when master post is updated?
- update_post_meta() whenever custom post type is updated
- Using preg_replace to filter custom textarea
- How to handle this specific case of custom post type?
- Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
- Create action running on trashed_post hook to modify post_meta value
- Advanced search form with filters for custom taxonomies and custom fields
- How to enqueue scripts on custom post add/edit pages?
- remove custom post type permalink
- 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
- Custom post type save_post action not firing
- 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
- How do I programmatically add items of content to a custom post type?
- Not Able to Insert Taxonomy Term Using wp_insert_post()
- Get all posts from custom post type and insert in select input as metabox
- How I upload, save and set a featured image from my frontend?
- 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
- How can I programmatically save data into custom fields that contain serialized data?
- Using pre_get_posts to Filter Posts
- Remove “Get Shortlink” button in admin of custom post type
- How to get Custom Post ID by adding filter to child theme’s function
- Add Post Url to Manage Edit Screen
- Display all custom post type posts and order them by an optional meta_key
- Is it possible to create a post using a metabox?
- How can I get_post_meta() in the most efficient way?
- need advice on how to do a lists using custom post types – taxonomy vs postmeta
- Auto-generated posts not showing in backend (but being counted!)
- Custom Post Status Transition Issues With Get Post Meta
- Set default Custom Post Meta Value
- List all images from a single post meta value
- Show the same Article Available in Other Categories
- how to delete all users and posts based on ‘user_meta’?
- Meta Key Value in current-user-only loop
- How to set YouTube video as featured image?
- How to implement a Google map store locator
- Displaying custom taxonomy in the admin list of a custom post type
- Widget: Custom Post Type Post Listing Dropdown on Admin Side
- Update Post Meta for a logged in user
- How to duplicate entire custom post type
- get_post_meta returning no value in custom post type alert email
- How to checked selected category checkbox when my custom post inserted from frontend
- WordPress request fiter order by related post’s post_title
- Getting thumbnails of a custom posts featured images in a page-templates metabox
- Remove Post Custom Meta Box
- If Post Meta Equals Current Title Conditional Advanced Custom Fields
- wp_insert_post wrong post type [closed]
- Display different information of a custom post type
- delete_post_meta() for whole CPT / multiple posts?
- 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 to show records that don’t have custom meta value
- $post->post_meta not pulling any post in wordpress/php
- WP_Query of custom post type sorted by meta_key has unexpected results
- WordPress hook which triggers on post import
- Get all metadata for a given custom post type
- importing table data to custom post type
- delete duplicate meta_value with same post_id
- Search CPT Title AND Meta
- Empty meta-box returns publishdate if no value is set?
- Building tags and archive using meta from custom post type
- 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
- What is the correct way that when creating a custom post type assign values to custom fields created with pods framework?
- How do I find out which (page) template file my custom child post is looking for?
- 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?
- Custom post type meta fields missing on save_post_type
- Order posts by meta value hiding posts instead of re-ordering
- custom search results – order results differently by post type
- How to get post meta for custom post type and taxonomy
- get_post_meta for Custom Post Type ( CPT )
- Complex strcuture as CPT or taxonomy for use in woocommerce product variations [closed]
- Add a image to a post published on a CPT from the front-end
- How to create content automatically when a post is published?
- Add auto increment value to custom meta
- Return only custom post types for the page, not all
- Retrieve post data via WPDB class
- Random meta field from specific custom post type
- Custom post type functions.php if statement on action
- Custom Post Type meta value is being saved in array, instead of just the string (as value)
- Custom Form Data save after Login User
- Post Meta for Custom Post Types