Skip to content

Instantly share code, notes, and snippets.

@dantetesta
Created September 6, 2023 12:11
Show Gist options
  • Save dantetesta/cc4b8f96c7edbde7811493fd59b2bf4e to your computer and use it in GitHub Desktop.
Save dantetesta/cc4b8f96c7edbde7811493fd59b2bf4e to your computer and use it in GitHub Desktop.
<?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