Proper formatting of post_date for wp_insert_post?

If you don’t add a post_date then WordPress fills it automatically with the current date and time. To set another date and time [ Y-m-d H:i:s ] is the right structure. An example below with your code. $postdate=”2010-02-23 18:57:33″; $new_post = array( ‘post_title’ => $title, ‘post_content’ => $description, ‘post_date’ => $postdate, ‘post_status’ => ‘publish’, ‘post_parent’ … Read more

How to set featured image to custom post from outside programmatically

Can’t this simply be done with media_sideload_image() ? Seems pretty simple. Only catch is if you aren’t on admin area, you must include some libraries from within WordPress includes: // only need these if performing outside of admin environment require_once(ABSPATH . ‘wp-admin/includes/media.php’); require_once(ABSPATH . ‘wp-admin/includes/file.php’); require_once(ABSPATH . ‘wp-admin/includes/image.php’); // example image $image=”http://example.com/logo.png”; // magic sideload … Read more

How do I set a featured image (thumbnail) by image URL when using wp_insert_post()?

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. Usage: Generate_Featured_Image( ‘../wp-content/my_image.jpg’, … Read more