0

パブリッシュ時に投稿 ID をカスタム テーブルに挿入しようとしていますが、正しい ID を追加していませんが、0 は私の関数です

//get post id on publish
function get_publishing_id($post_id) {
  $post= get_post($post_id);
  if ($post->post_type == 'post'
      && $post->post_status == 'publish') {

        // insert data on publish
        global $wpdb;
        $wpdb->insert( 
            $wpdb->prefix.'banner_views', 
            array( 
                'postid' => $post,
                'view_count' => 12,
            )
        );

  } // end if
} // end function
add_action('save_post','get_publishing_id');

これを解決するのを手伝ってください。どうもありがとう...

4

1 に答える 1

0

解決しました。

間違いは $post->ID のように $post で ID を渡していませんでした

//get post id on publish
function get_publishing_id($post_id) {
  $post= get_post($post_id);
  if ($post->post_type == 'post'
      && $post->post_status == 'publish') {

        // insert data on publish
        global $wpdb;
        $wpdb->insert( 
            $wpdb->prefix.'banner_views', 
            array( 
                'postid' => $post->ID,// here was the mistake
                'view_count' => 12,
            )
        );

  } // end if
} // end function
add_action('save_post','get_publishing_id');

したがって、上記のコードは私にとってはうまくいきます。

どうもありがとう

于 2012-10-02T11:33:16.820 に答える