WordPress upload http error gif
While looking through the function reference entry for wp_insert_post(), I noticed that there’s no parameter in the array it requires which will allow me to set the ‘Featured Image’ for a post, displayed as the post thumbnail in my theme.
I have looked into functions like set_post_thumbnail(), as suggested by Mr. Bennett, but this seems to be a relatively new addition to WordPress itself and the WordPress codex. As such, there aren’t any sources that I can find which explain how the $thumbnail_id parameter should be acquired and supplied. If this really is the function to use, in what way could I provide it with a valid $thumbnail_id parameter when all I have is an image URL?
Thanks in advance!
You can set an image as post thumbnail when it is in your media library. To add an image in your media library you need to upload it to your server. WordPress already has a function for putting images in your media library, you only need a script that uploads your file.
EDIT: Added path creation
Edit by Otto: You clarified your question, so I’ll clarify the response Chip gave.
Basically, you need to make the ‘attachment’ for the post as well. When an image is uploaded into the WordPress media library, a special post entry is made for it with a post type of attachment. This attachment is linked to some specific post via the post_parent identifier.
So if you know the ID of the attachment, then calling set_post_thumbnail with the post object or ID and the attachment ID will simply set the post thumbnail flag.
If you have not created the attachment yet, then you will need to do that first. Easiest way to do that is with wp_insert_attachment() . This function takes an array of a few parameters, the filename (the file must already be in the proper uploads directory), and the post ID of the parent post that you want to attach the attachment to.
Just having a file uploaded and attached to a post doesn’t do anything automatically. This is simply a sort of categorization mechanism. The gallery mechanism, for example, uses the attached images of a post to build the for that post. A thumbnail for a post is just one of the attached images which has be set to be the thumbnail.
More info on how to use wp_insert_attachment can be found in the codex (linked above).
Migrating your WordPress Database
In this lesson, we will show you how to migrate our WordPress website. In this fictional tutorial we will migrate a your-wordpress-site.com from HostABC to InMotion Hosting. As to provide no downtime during the migration process , we will not update the nameservers for your-wordpress-site.com, so the hosting will remain pointed to the previous host, in this case HostABC. Once we have performed the migration and tested the site, we will then update the domain’s nameservers and point them over to InMotion Hosting.
Exporting a Backup of your WordPress Database
The way WordPress works is all of your content that you have written for your website is stored in your database. phpMyAdmin is a hosting industry standard for managing MySQL databases, and many hosts provide this tool for their users to use. Since this tool is widely available, we will show you how to use phpMyAdmin to downlaod a backup of your existing database.
- At your previous host, access phpMyAdmin.
- Load your WordPress database by clicking the database name in the left hand menu pane.
- Click the "export" tab at the top right.
- Under "export, highlight all the tables and select "SQL". These are the default settings.
- Under "options" make sure that "add DROP TABLE/ VIEW/ PROCEDURE/ FUNCTION" is selected.
- Ensure that "Save as File" towards the bottom of the page is selected.
- Click Go
This is prompt you to download the backup file.
Creating a NEW MySQL Database
To be able to import the database you just exported from your previous host, you will first need to create a blank database.
- Log into your cPanel account with InMotion Hosting.
- Click the "MySQL Database Wizard" link.
- In Step 1 of the Wizard, enter a name for your new databse. You can name your database whatever you would like, just be sure to write this down somewhere for future reference.
- In Step 2 of the Wizard, enter a database username and password. You can enter anything you would like as the user, please make a note of the username and password for future reference.
- In Step 3 of the Wizard, select "ALL PRIVILEGES" and click "Next Step"
Importing the Backup you Created
- Log into your InMotion Hosting cPanel account.
- Click on the "PHPMyAdmin" icon.
- Select the database you just created.
- Click "Import" in the top right.
- Click the "Browse" button and select the database backup file on your computer that you created earlier.
- Click "Go"
You have now completed migrating your WordPress database, congratulations! The next step in the process is to migrate your WordPress application files.
Please check the next article on Migrating WordPress Files. If you missed our previous article, please see the Migrating your WordPress Site Data tutorial. For more information on this course please visit Migrating your Existing WordPress site to InMotion Hosting.
Please check the next article on Testing your WordPress website after Migration. If you missed our previous article, please see the Migrating WordPress Files tutorial. For more information on this course please visit Migrating your Existing WordPress site to InMotion Hosting.