0
votes

I am trying to get_post_meta from wp_postmeta to copy to a plugin table wp_wpgmza when a post is published. Using a save_post action hook correctly copies dat from the wp_post table but I get blank fields for wp_postmeta.

I have tried using a publish_post action hook but this also returns blanks.

This is the latest function I have been;

function map_update($ID, $post) {
//if ($post->post_type = 'post') return;
    $link = get_permalink ( $ID );
    $title = get_the_title ( $ID );
    $mapaddress = get_post_meta ( $ID, 'address', true );  
  global $wpdb;

    $table = $wpdb->prefix . 'wpgmza';

    $data = array(
                'link' => $link,
                'title' => $title,
                'address' => $mapaddress,

            );

    $wpdb->insert($table , $data);
}
add_action('publish_post', 'map_update' );
1
are you try $mapaddress = get_post_meta ( $post->ID, 'address', true );Yatendra

1 Answers

-1
votes

please check I cahnged argument to $post_id may be you get your solution

function map_update($post_id) {
$ID=$post_id;
//if ($post->post_type = 'post') return;
    $link = get_permalink ( $ID );
    $title = get_the_title ( $ID );
    $mapaddress = get_post_meta ( $ID, 'address', true );  
  global $wpdb;

    $table = $wpdb->prefix . 'wpgmza';

    $data = array(
                'link' => $link,
                'title' => $title,
                'address' => $mapaddress,

            );

    $wpdb->insert($table , $data);
}
add_action('publish_post', 'map_update' );