How to set post slug when using wp_insert_post();?

My theme uses a custom template to render some contents. To use this template, I’m hooking into after_switch_theme to create my own page after the theme is activated, and then assign this template to it. This is how I do it: $new_page_title = __(‘Custom page’); $new_page_content=””; $new_page_template=”page-custom.php”; $page_check = get_page_by_title($new_page_title); $new_page = array( ‘post_type’ => … Read more

Proper formatting of post_date for wp_insert_post?

What is the proper way to define the post date when submitting a post from the front end using wp_insert_post (Trac)? My snippet now is publishing with the mysql time… if (isset ($_POST[‘date’])) { $postdate = $_POST[‘Y-m-d’]; } else { $postdate = $_POST[‘2011-12-21’]; } // ADD THE FORM INPUT TO $new_post ARRAY $new_post = array( … Read more

How to set featured image to custom post from outside programmatically

I am trying to fetch and insert images outside the wordpress environment to a custom post via PHP. How to move/upload that image to wordpress upload directory year date folder format just like wordpress do and set that image to featured image against the custom post? Also to upload image to custom post gallery? Below … Read more

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

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 … Read more