anishrip23
Regular Member
- Jul 17, 2011
- 206
- 79
Hello guys,
The title says all
i have got a script from some thread on bhw to create post automatically
code-
add_action('add_attachment', 'create_post');
function create_post( $attach_ID ) {
$attachment = get_post( $attach_ID );
$my_post_data = array(
'post_title' => $attachment->post_title,
'post_type' => 'post',
'post_category' => array('0'),
'post_status' => 'publish'
);
$post_id = wp_insert_post( $my_post_data );
// attach media to post
wp_update_post( array(
'ID' => $attach_ID,
'post_parent' => $post_id,
) );
set_post_thumbnail( $post_id, $attach_ID );
return $attach_ID;
}
But when i put this code in functions.php and upload images via ftp client it only shows image on thumbnail but it doesn't show any image on the content post.
It does all things create post with title on the image file, add featured image to thumbnail but no image on post page.
Can anyone help me out? It is pain in ass when i upload images and then create the post manually from each image.
Thanks!
The title says all
i have got a script from some thread on bhw to create post automatically
code-
add_action('add_attachment', 'create_post');
function create_post( $attach_ID ) {
$attachment = get_post( $attach_ID );
$my_post_data = array(
'post_title' => $attachment->post_title,
'post_type' => 'post',
'post_category' => array('0'),
'post_status' => 'publish'
);
$post_id = wp_insert_post( $my_post_data );
// attach media to post
wp_update_post( array(
'ID' => $attach_ID,
'post_parent' => $post_id,
) );
set_post_thumbnail( $post_id, $attach_ID );
return $attach_ID;
}
But when i put this code in functions.php and upload images via ftp client it only shows image on thumbnail but it doesn't show any image on the content post.
It does all things create post with title on the image file, add featured image to thumbnail but no image on post page.
Can anyone help me out? It is pain in ass when i upload images and then create the post manually from each image.
Thanks!