I’m making an attempt to vary the title of a customized put up kind “property”, i attempted some ways.
- publish_property (ref: {$new_status}_{$post->post_type} Hyperlink)
- save_post (ref: save_post Hyperlink)
- wp_after_insert_post (ref: Hyperlink)
present code
add_action( 'publish_property', 'modify_property_url', 120, 3);
perform modify_property_url( $post_id, $put up, $old_status )
{
if ( $post_parent_id = wp_get_post_parent_id( $post->ID ) ) {
$post_id = $post_parent_id;
}
$addressArr = get_post_meta( $post_id, 'fave_property_address', true ); //would not work, god is aware of why
$handle = $addressArr;
$addressCommasRemoved = (explode(",",$handle));
$addressCommasRemoved = be part of("", $addressCommasRemoved);
$addressSpacesRemoved = (explode(" ",$addressCommasRemoved));
$newUrl = be part of("-", $addressSpacesRemoved);
$post_update = array(
'ID' => $post->ID,
'post_title' => $newUrl
);
wp_update_post( $post_update );
}
Widespread Errors tried to keep away from:
- “property” is the put up kind.
- tried altering the precedence upto 700 would not works
P.S: the identical code ( get_post_meta() ) when ran outdoors these hooks and actions works!