I am trying to insert post id on publish to custom table but it is not adding correct id but 0
here is my function
//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');
Please help to solve this. Thanks a lot…
It’s solved.
The mistake was not passing ID with $post like $post->ID
So above code works for me.
Thanks a lot