Wordpress得到的帖子并不适用于所有情况

时间:2014-10-14 15:19:41

标签: php wordpress

我想获得一篇文章的帖子。它适用于updated_post的情况,但不适用于new_post,我只是想不出原因..

这是案件的功能:

 function userpro_sc_new_post( $new_status, $old_status, $post ) {
global $userpro_social;
$exclude = userpro_sc_get_option('excluded_post_types');
if ($exclude != ''){
    $exclude_types = explode(',',$exclude);
} else {
    $exclude_types = array('nav_menu_item');
}
if (!in_array($post->post_type, $exclude_types )) {
    // new post
    if ( $new_status == 'publish' && $old_status != 'publish' ) {
        $user = get_userdata($post->post_author);
        $userpro_social->log_action( 'new_post', $user->ID, $post->ID, $post->post_title, $post->post_type );
    }
    // updated post
    if ($new_status == 'publish' && $old_status == 'publish' ){
        $user = get_userdata($post->post_author);
        $userpro_social->log_action( 'update_post', $user->ID, $post->ID, $post->post_title, $post->post_type );
    }
}

}

这是在案例中运行的代码:

function log_action($action, $user_id, $var1=null, $var2=null, $var3=null) {
global $userpro, $userpro_social;
$activity = get_option('userpro_activity');
$timestamp = current_time('timestamp');

$status = '';

switch($action){


    case 'new_post':
        $myId = get_post_meta(get_the_ID(), 'wpex_post_video_oembed', true);
        $status .= $myId;

        break;

    case 'update_post':
        $myId = get_post_meta(get_the_ID(), 'wpex_post_video_oembed', true);
        $status .= $myId;
        break;

        }

就像我说的那样,update_post工作,所以我可以看到ID ... new_post实际上有效,但我无法在这里获取ID。为什么呢?

我简化了代码运行,但它仍然是同一个问题。

请帮忙!

0 个答案:

没有答案