1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Black Hat SEO' started by anishrip23, Feb 6, 2014.

  1. anishrip23

    anishrip23 Regular Member

    Joined:
    Jul 17, 2011
    Messages:
    210
    Likes Received:
    78
    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!
     
  2. fxphil

    fxphil Senior Member

    Joined:
    Jul 16, 2010
    Messages:
    1,084
    Likes Received:
    504
    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: Feb 7, 2014
  3. anishrip23

    anishrip23 Regular Member

    Joined:
    Jul 17, 2011
    Messages:
    210
    Likes Received:
    78
    Thanks for you reply
    But this plugin is to add thumbnails to images.
    It doesn't post image to the content page.
     
  4. anishrip23

    anishrip23 Regular Member

    Joined:
    Jul 17, 2011
    Messages:
    210
    Likes Received:
    78
    expecting more advices from you guys.
    Hope my problem will be solved.
    Any more suggestions??
     
  5. anishrip23

    anishrip23 Regular Member

    Joined:
    Jul 17, 2011
    Messages:
    210
    Likes Received:
    78
    Is there any solution for this? Or it can not be done.
    It means there is no way to do that
     
  6. boomboomer

    boomboomer Executive VIP

    Joined:
    Feb 7, 2008
    Messages:
    705
    Likes Received:
    865
    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
     
  7. anishrip23

    anishrip23 Regular Member

    Joined:
    Jul 17, 2011
    Messages:
    210
    Likes Received:
    78
    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?
     
  8. boomboomer

    boomboomer Executive VIP

    Joined:
    Feb 7, 2008
    Messages:
    705
    Likes Received:
    865
    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 Thanks x 1
  9. rkwebs

    rkwebs Power Member

    Joined:
    Sep 23, 2010
    Messages:
    602
    Likes Received:
    87
    Occupation:
    IT
    Location:
    India
    Home Page:
    I have a plugin i modified its work well if u need let me know :)
     
  10. saqr2

    saqr2 Newbie

    Joined:
    Jan 13, 2014
    Messages:
    31
    Likes Received:
    3
    i saw a plugin does the same things
     
  11. anishrip23

    anishrip23 Regular Member

    Joined:
    Jul 17, 2011
    Messages:
    210
    Likes Received:
    78
    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.
     
  12. vsk007

    vsk007 Newbie

    Joined:
    Mar 26, 2010
    Messages:
    1
    Likes Received:
    0
    Plugin name please.. or please share it..

    Thanks.
     
  13. todordonev

    todordonev Regular Member

    Joined:
    Nov 23, 2012
    Messages:
    379
    Likes Received:
    228
    Gender:
    Male
    Location:
    Bulgaria
    Home Page:
    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