Created
September 6, 2023 12:11
-
-
Save dantetesta/cc4b8f96c7edbde7811493fd59b2bf4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'jet-engine/custom-content-types/item-to-update', function( $item, $fields, $handler ) { | |
$post_id = ! empty( $item['cct_single_post_id'] ) ? absint( $item['cct_single_post_id'] ) : false; | |
if ( ! $post_id ) { | |
return $item; | |
} | |
$post = get_post( $post_id ); | |
$has_single = $handler->get_factory()->get_arg( 'has_single' ); | |
if ( ! $post || ! $has_single ) { | |
return $item; | |
} | |
$title_field = $handler->get_factory()->get_arg( 'related_post_type_title' ); | |
$postarr = array( | |
'ID' => $post_id, | |
); | |
if ( $title_field ) { | |
$postarr['post_name'] = isset( $item[ $title_field ] ) ? $item[ $title_field ] : ''; | |
} | |
wp_update_post( $postarr ); | |
return $item; | |
}, 0, 3 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment