How to make image post automatically from each image upload on wordpress?

anishrip23

Regular Member
Joined
Jul 17, 2011
Messages
206
Reaction score
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!
 
Not 100% sure but have you tried a plugin called "get the image" Check out it's code, it may be able to help you out. I hate to see unanswered questions on the forum but that's the best I have for ya.
 
Last edited:
Not 100% sure but have you tried a plugin called "get the image" Check out it's code, it may be able to help you out. I hate to see unanswered questions on the forum but that's the best I have for ya.

Thanks for you reply
But this plugin is to add thumbnails to images.
It doesn't post image to the content page.
 
expecting more advices from you guys.
Hope my problem will be solved.
Any more suggestions??
 
Is there any solution for this? Or it can not be done.
It means there is no way to do that
 
You have set the media as a thumbnail using:

Code:
set_post_thumbnail( $post_id, $attach_ID );

If you want to add the image in the main post, you'll have to

1. Get the URL of the image
2. Add the post content containing the <img> tag with the source set to this URL
 
You have set the media as a thumbnail using:

Code:
set_post_thumbnail( $post_id, $attach_ID );

If you want to add the image in the main post, you'll have to

1. Get the URL of the image
2. Add the post content containing the <img> tag with the source set to this URL

Hey
thanks for your reply
As i am not a coder i didn't understand how to do that
is this correct set_post_content ( <img> )
And where to place source to set url? I have searched almost every where but didn't find any guide to do that.
Could you please look into this for me?
 
Try this
Code:
[COLOR=#ffff00][B]$imageUrl = wp_get_attachment_image_src( $attach_ID);[/B][/COLOR]


$my_post_data = array(
'post_title' => $attachment->post_title,
'post_type' => 'post',
'post_category' => array('0'),
[COLOR=#ffff00][B]'post_content' => "<img src='$imageUrl'/>",[/B][/COLOR]
'post_status' => 'publish'
);
 
I have a plugin i modified its work well if u need let me know :)
 
Try this
Code:
[COLOR=#ffff00][B]$imageUrl = wp_get_attachment_image_src( $attach_ID);[/B][/COLOR]


$my_post_data = array(
'post_title' => $attachment->post_title,
'post_type' => 'post',
'post_category' => array('0'),
[COLOR=#ffff00][B]'post_content' => "<img src='$imageUrl'/>",[/B][/COLOR]
'post_status' => 'publish'
);
Thanks for the code
It worked a little bit. It shows image on content page but the size of that image was same as thumbnail.
But now i have purchased a plugin from someone.
 
Thanks for the code
It worked a little bit. It shows image on content page but the size of that image was same as thumbnail.
But now i have purchased a plugin from someone.

Plugin name please.. or please share it..

Thanks.
 
I'm not sure what are you searching for but here's some suggestions:
If you want to upload image via wordpress and it to appear as content and thumbnail - "auto featured image"
If you are linking image from other website and you want to save it to your default wp uploads folder - search "get the image"
If you want to make posts from bulk uploading images - "Fuxy's WP Images 2 Posts" combine with "auto featured image"

These days there are plugins for everything - you just have to use the search wisely
 
Back
Top