Thursday, September 22, 2022
HomeWordPress Developmentput up meta - get_post_meta() returns nothing in save_post, publish_post, wp_after_insert_post

put up meta – get_post_meta() returns nothing in save_post, publish_post, wp_after_insert_post


I’m making an attempt to vary the title of a customized put up kind “property”, i attempted some ways.

  1. publish_property (ref: {$new_status}_{$post->post_type} Hyperlink)
  2. save_post (ref: save_post Hyperlink)
  3. 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:

  1. “property” is the put up kind.
  2. 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!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments