This function inserts posts (and pages) into the database. It sanitizes variables, does some checks, fills in missing variables like date/time, etc. It takes an array as its argument and returns the post ID of the created post (or 0 if there is an error).

learn more… | top users | synonyms

0
votes
1answer
25 views

wp_insert_post not working fine

I asked my question on stackoverflow but I did not get any answer, may be because it's the question related to Wordpress.So I am asking it here. I am using wp_insert_post function to insert my posts, ...
1
vote
1answer
27 views

wp_insert_post() getting slower the more posts

I have written a bulk import script where I import posts with the wp_insert_post() function and add 1 meta value and 1 term to the post. I have done 6 times of 7000 posts now, but for some reason the ...
0
votes
1answer
330 views

Front end posting

This source works with image upload. Without image upload, it works, but 'redirect' doesn't work. What should I do?? Any suggestions to what the problem might be? if( 'POST' == ...
1
vote
1answer
472 views

Organizing uploaded media with wp_insert_post() and wp_handle_upload according to time parameter

I'm retroactively creating a post with wp_insert_post() and attaching a featuring image to it. I need the image to go into the folder that corresponds to the post's publishing date. I'm using time ...
2
votes
1answer
340 views

Programmatically adding posts

I'm about to create parser which would be inserting new custom posts. So, it's pretty simple global $user_ID; $new_post = array( 'post_title' => 'My New Post', 'post_content' => 'Lorem ...
0
votes
1answer
367 views

wp_insert_post not working for custom post type?

For whatever reason wp_insert_post doesn't work for a custom post type. Here's the code snippet I'm using. $new_post = array( 'post_type' => 'rsp_synonym', 'post_title' => ...
0
votes
2answers
24 views

wp_insert_post at same time as saving post results in 502 Bad Gateway

I'm currently trying to create/update one post while also saving the current post that I'm on. It's all happening here: add_action('save_post', 'wysiwyg_save_meta'); function wysiwyg_save_meta(){ ...
0
votes
1answer
178 views

Insert data from custom created PHP page into wp_postmeta table

I am working with a Wordpress site and have created a custom page in /home/planmyme/public_html/php/ with the name response.php. On this page I am getting a value to insert in the wp_postmeta table ...
0
votes
1answer
866 views

wp_insert_post does not write my post_name

i tried to generate a page via wp_insert_post. That works fine except that the post_name is always written with the same value as the post_title. Here comes the code snippet: // Create homesite if ...
0
votes
1answer
28 views

How can I programmatically save data into custom fields that contain serialized data?

I purchased a theme from themeforest recently that has a custom post type. Here is a link to a page that's been created with the custom post type: ...
0
votes
1answer
48 views

How do I programmatically add items to a custom post type?

I have a custom post type to which I'd like to programmatically import data. I have followed these instructions and these, and I can easily do it for WP typical pages and posts. However, my custom ...
4
votes
1answer
984 views

Create posts on user registration

How can I create let say 3 posts after the user finish the registration ? The ideal outcome would be to create 3 posts using the user as the author of the posts and with some pre-defined values. ...
3
votes
1answer
283 views

Endless loop with wp_insert_post and wp_update_post

I have an array $unqiues which contains URL's, I loop over the array with the code below to get the URL titles, insert a new post, update the post meta. Then I change the the posts title and name to ...
0
votes
4answers
4k views

Prevent duplicate posts in wp_insert_post using custom fields

My source links are something linke this : http://sample.com/entertainment/default.aspx?tabid=2305&conid=102950 http://sample.com/entertainment/default.aspx?tabid=2418&conid=104330 ...
0
votes
1answer
16 views

Changing wp_insert_post() location

I know that wp_insert_post() insert posts into wp_posts table. I want to change that to insert posts into lets say wp_posts2. Can I do that? I need to do this because I don't want to mess data from ...
0
votes
0answers
20 views

save_post action not firing due to old page_template meta data

I have some functionality hooked to the save_post action that wasn't working for a user on a particular WordPress Page. After some digging I found that wp_insert_post() was returning before getting ...
3
votes
1answer
260 views

Insert new term during new post creation

i am currently working on a snippet to insert a new post dynamically (it's a custom post type). During this new post creation i need to insert terms in custom taxonomies associated to the custom post ...
9
votes
3answers
23k views

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, ...
0
votes
0answers
18 views

add_post_meta from front end form

I am trying to add new post and meta data from the front end. I have a form and a custom post type named 'parts'. Looking for the easiest way of adding meta box and passing a value from the front end ...
0
votes
1answer
90 views

Create new Wordpress post [wp_insert_post] based on results of a WP_Query

I have a a page where users can filter a list of custom post-type posts based on the "Ultimate WP Query Search Filter" plugin. Results are passed to a div on the page using AJAX from there users can ...
0
votes
0answers
22 views

Creating multiple functions for front-end forms

I have the following situation (which I simplified for didactical purposes): page-books.php: <form> <input type="text" name="title" /> <input type="text" name="sinopsis" /> ...
1
vote
1answer
133 views

How I upload, save and set a featured image from my frontend?

I have a form in my site. This the user register one missing person. I created a custom post type missing person, custom taxonomies and custom fields. All this input's save as well in wp. But I ...
0
votes
1answer
109 views

Action hook “wp_insert_post” works but not for last imported post

I want to run a custom function whenever posts are imported to my custom post type. I am currently running this code - function on_post_import($post){ global $wpdb; $results = ...
0
votes
1answer
223 views

WordPress Frontend Post Form (Bootstrap Modal) Not Creating Post

I have a form in a separate PHP file in the theme directory and it's being included in the sidebar of the main page template. The form is inside a Boostrap modal. I've been trying to use this code to ...
0
votes
1answer
54 views

wp_insert_post Only creates draft

When I call wp_insert_post() with a post status, it only creates posts with "Draft" status. I've tested it with WordPress built-in statuses and my custom post statuses. But it only creates Draft ...
0
votes
2answers
58 views

post_categories array using variable

When using wp_insert_post can I do something like: $categories = '1,2,3,4,5' ...and then... 'post_category' => array($categories)
0
votes
0answers
34 views

wp_insert_post questions

I'm trying to add posts using wp_insert_post, but a few issues occur. First the code: function importposts() { $fh_import = @fopen( dirname( __FILE__ ) . '/importposts.txt', 'r' ); if ( ...
0
votes
0answers
39 views

wp_insert_post hook not being called with wp_publish_post or wp_insert_post?

I have a plugin that converts hashtags (any text that starts with #) into Wordpress tags. It's working great when I manually create a post via the Wordpress dashboard, but doesn't work when I ...
0
votes
0answers
53 views

Grab the Post ID created by wp_insert_post($post)

Okay apparently there have been at least a few people already asked this question (1, 2), but none seems to get the right answer... wp_insert_post() and the following update_post_meta() & ...
0
votes
1answer
60 views

wp_insert_post -> post_content not showing

I have a problem with wp_insert_post. When I'm attempting to insert my post, the post_content essentially shows up as just blanks spaces. I even went into MySQL to confirm. Everything else, ...
0
votes
1answer
35 views

Save the Post ID from wp_insert_post($post); into a text file?

I'd like to create some posts using wp_insert_post and then save the created posts' Titles and ID's into a text file for future reference. How could this be done?
0
votes
1answer
32 views

importing table data to custom post type

i'm trying to import data from table to custom post types below is the code i'm using but this $row['Title'] return nothing ... if i hard code it works $rows = $wpdb->get_results( "SELECT * FROM ...
0
votes
1answer
21 views

Inserting current user ID into Post for Author

I am trying to insert the user id of the current user when creating a custom post type. This is my code: $my_post = array( 'post_title' => $orderRequestCode.' - ' . $customerName, ...
1
vote
2answers
90 views

wp_insert_post to schedule a post - but nothing happens?

I'm trying to schedule a post that is currently a draft: function schedule() { $postdate = date('2014-06-11 00:30:00'); $post = array( 'ID' => 11, 'post_status' => 'future', ...
0
votes
1answer
20 views

wp_insert_post removes information when updating

I'm using a front-end form and wp_insert_post to update posts from the front-end of a website - in order to do this I am using: 'ID' => get_the_ID(), to make sure it is updating the current post ...
0
votes
1answer
75 views

wp_insert_posts Fatal error: Maximum function nesting level of '100' reached, aborting!

I'm having a weird problem I have written the code as below: add_action('save_post', 'save_post_func'); function save_post_func(){ include_once(ABSPATH . WPINC . '/feed.php'); $rss = ...
0
votes
1answer
54 views

wp_insert_post does not insert string with apostrophes correctly

I'm using wp_insert_post (for several reasons) in a script I'm writing and it's causing any string that has an apostrophe in it to be truncated up to that character (including the character). Here's ...
0
votes
0answers
45 views

wp_insert_post not working

I'm using WP 3.8.3 + Yoast for SEO + custom fields. Trying to do wp_insert_post due to post migration using the $my_post = array( 'post_title' => $post_tit , 'post_content' => $link, ...
0
votes
1answer
30 views

Unicode characters are saved in a funny way in the DB

I have a custom website in which I am using wp_insert_post() to manually create posts that have a title which has characters thare are non-English Unicode letters (Arabic to be more specific). The ...
0
votes
0answers
35 views

add_post_meta displays in admin edit area

I use a simple way to add_post_meta() to wp_insert_post(). Everything's working fine, except my meta box doesn't appear in admin area. Is there a simple way to do that? <?php $condition = ...
0
votes
1answer
97 views

Problem with wp_insert_post

i'm sorry for my english. I have a problem with the function wp_insert_post in a script. I'm trying to create a new post when i receive a notification from paypal. Everything works fine untill i try ...
0
votes
0answers
49 views

Automatically add another subpost of the same parent when a subpost is saved

I figured it out how to add one subpost when a post is saved. But now I need to know how I can get another subpost of the same parent when a subpost is saved. Could anybody help me out? This is what ...
0
votes
0answers
57 views

Slash is being stripped in my post_name when using wp_insert_post

I want a permalink with slashes : e.g. http://mysite.com/keyword1/keyword2/mypage.html I have put it in the param "post_name" in wp_insert_post but the slashes are stripped, so the result is ...
2
votes
2answers
864 views

Faster way to wp_insert_post & add_post_meta in bulk

I have a csv file that I want to insert that consists of ~1,500 rows and 97 columns. It takes about 2-3 hours to do a full import and I'd like to improve this if there is a way. Currently for each ...
0
votes
1answer
87 views

Check for duplicate custom field value before running wp_insert_post

That is, I want to prevent 'guid_review' ACF value being duplicate by checking it before creating the post. foreach ($items as $itemKey => $item) { $myPost = array( ...
0
votes
0answers
40 views

How to speed up wp_insert_post()

I m creating a management tool for a company. The website would always be on intranet and would never go online. WordPress has everything I needed however I m stuck at a point. I have given the ...
0
votes
2answers
37 views

Is there a way to fire other functions from wp_insert_post

I am creating a new post using the wp_insert_post function. Here's what that code looks like: $new_post = array( 'post_title' => $newtitle, 'post_status' => 'publish', ...
0
votes
0answers
59 views

wp_insert_post another database with custom field

wp_insert_post with the command you want to transfer the contents to another database, I use the following command <?php require('wp-config.php'); $conn = mysql_connect($dbHost, $dbUser, ...
0
votes
1answer
127 views

Bug in wp_insert_post script and form, probably something simple I am not seeing

OK, I have been working on debugging this script for 2 and a half days now and am coming up empty. Basically, this is a front end form that will insert posts based on the script that I wrote for it at ...
2
votes
2answers
224 views

wp_insert_post() Callback?

After I added a post by wp_insert_post(); Any callback after I added ? I need permalink of added post. I have idea only search by title and post-type (I use custom post-type in my case), But any ...