2015-11-03 73 views
0

我试图从wp_postmeta get_post_meta复制到插件表wp_wpgmza当一篇文章发布。 使用save_post操作挂钩可以正确地从wp_post表中复制dat,但是我得到了wp_postmeta的空白字段。get_post_meta with save_post或publish_post动作钩子

我已经尝试使用publish_post操作挂钩,但这也返回空白。

这是我一直以来的最新功能;

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'); 
+0

你尝试$ mapaddress = get_post_meta($后> ID, '地址',真正的); – Yatendra

回答

-1

请我cahnged参数$ POST_ID可能是你得到你的解决方案

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'); 
+0

谢谢@vrajesh!我意识到我没有提到该帖子是由插件生成的,而不是WP后端生成的。所以我正在将这个函数写入插件,并希望这能起作用。再次感谢。 – Douro