Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8133477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:36:54+00:00 2026-06-06T09:36:54+00:00

I defined image dimensions in media (WP) and in functions.php addedd some 2 custom

  • 0

I defined image dimensions in media (WP) and in functions.php addedd some 2 custom dimensions for image upload. When I upload images through WP admin everything is ok.

But now I have client which is uploadin 100 images via FTP to some folder on his site and I was wondering if there is a way to add this image to post programmatically?

Every image has name like post_ID.jpg (for exam. 450.jpg) and this is how I will know which image to add to which post but my question is how to add programmatically with wp functions (resize/crop (like it does when i add via WP admin)).

This images are in custom folder: /product_images/

Thank’s for help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:36:55+00:00Added an answer on June 6, 2026 at 9:36 am

    Solved..

    here is a solution:

    $post_id = 809; // example post_ID
    $filename= '/my_images/809.jpg';
    $description = 'some description';
    
    # remove all attachments
    $wpdb->query("UPDATE post_parent ='0' WHERE post_type='attachment' AND post_parent='".$post_id."'");
    
    # upload / resize / crop image (to WP images folder)
    media_sideload_image($filename,$post_id,$description);
    
    $last_attachment = $wpdb->get_row($query = "SELECT * FROM {$wpdb->prefix}posts ORDER BY ID DESC LIMIT 1", ARRAY_A);
    $attachment_id = $last_attachment['ID'];
    
    # set featured image
    add_post_meta($post_id, '_thumbnail_id', $attachment_id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build some image algebra code that can work with images (basically
I have a PHP image upload system which allows a user to upload various
This is the startup image defined in XAML: Source=/MyApp;component/media/person.png Then I replaced it in
I have an image that has a nested context menu defined in the XAML
Take a look at the image below. I defined the red boxes inside the
I'd like to use the image property tag constants defined in GDI+ from .NET.
I have an image in my code, as defined here var imageObj = new
I am using backstretch to create a fullscreen background slideshow using the images defined
I am confused in deciding the dimensions for a background image for my website.
I need to obtain the dimensions of an image, using a dynamically created image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.