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

1
vote
1answer
49 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
39 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
38 views

Insert data from custom created php page to wp_postmeta table

Hi i am working wordpress site here i have created one custom page in bellow directory /home/planmyme/public_html/php/ with the name response.php. on this page i am getting some value that value i ...
0
votes
1answer
66 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
35 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
19 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
21 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
21 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
39 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
27 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
22 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
12 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, ...
0
votes
1answer
31 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, ...
1
vote
2answers
50 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
17 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
35 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
35 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
35 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
21 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
27 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
78 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
40 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
37 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 ...
0
votes
1answer
45 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
31 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
31 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
40 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
89 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 ...
1
vote
1answer
43 views

Permalink for custom post type

I have created a custom post type called job. Posts are generated with wp_insert_post(), and that works perfectly fine. My problem is that the permalinks to those posts are either wrong or I have done ...
1
vote
1answer
85 views

tax_input argument for wp_insert_post()

I'm trying to insert custom taxonomies using wp_insert_post() and the tax_input argument, but it doesn't work. I want to set a post to a custom taxonomy ('types') and a category ('cars') $new_post = ...
0
votes
1answer
138 views

wp_insert_post bulk import 500 server error

I am working on a Wordpress import tool, where I use a custom city table in my database with longitude, latitude which combine with some other text and then import by wp_insert_post(). This works ...
0
votes
1answer
38 views

Custom Post Type not showing anything added by code anymore?

So I have a piece of code written and it worked before, hasn't been edited hasn't been changed, no updates on the WP DB no updates on any plugin on WP and it's suddenly not working correctly. This ...
0
votes
1answer
45 views

Do I need to deal with WordPress SQL Injection

Do I need to prepare strings against MySQL Injection when inserting into the database using a WordPress comments function such as this: $data = array( 'comment_post_ID' => $post_id, ...
0
votes
1answer
48 views

Setting a featured image while creating the post

I am creating a post with wp_insert_post/wp_update_post. The post should have a featured image. But to set a featured image I need the postID. The problem is I do not have any postID. What I am doing ...
0
votes
1answer
100 views

Issues with post_content when using wp_insert_post

I have a very weird problem and I would really appreciate your help with it. I am using wp_insert_post when a user submits a post. It works fine when I submit the form (i.e. the admin of the ...
0
votes
0answers
37 views

Post author for revision not being set on update/insert

I'm trying to programmatically update a custom-type post with revisions enabled via form, and everything seems to be working fine except the post_author field for the revision is being set to 0 ...
0
votes
0answers
21 views

Move post from one blog to another on same server with different prefixed tables

I have one blog at example.com and another at example.com/other (use same database - different prefix) What I am trying to accomplish is moving post(conditionally by custom field value) to either ...
0
votes
1answer
25 views

foreach $FILES create post how to

I know this is probably super easy and I am overlooking something here. I have a form on the front-end of our website where users can upload an image via a form and it creates a product in our shop. ...
0
votes
3answers
95 views

Conditionally set post_content in wp_insert_post

Is it possible to conditionally set the post_content in wp_insert_post? Im using a foreach to add multiple pages at once: foreach ($create_pages as $new_page) { $add_pages = array( ...
0
votes
2answers
21 views

Is there anything special I have to think of when setting post_date_gmt when inserting a new post?

I'm inserting information from a user into a custom post type. $current_user it a user-object. Is there anything special I have to think of when setting post_date_gmt when inserting a new post with ...
0
votes
1answer
58 views

Creating and populating custom nav menu (menu-item-position not working)

Im automatically creating pages with the below code, after that I create a custom menu and insert all the pages to this menu. $create_pages = array('Home', 'About', 'Contact'); // there will be more ...
0
votes
1answer
204 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' => ...
1
vote
1answer
172 views

What is considered the post's creation date for wp_insert_post?

I have the following hook which sets a default "hotness" for a post. For context, hotness is a meta_value saved to the post, and changes every time someone upvotes or downvotes the post. I use this ...
0
votes
1answer
24 views

wp_insert_post featured image from library

I know there are a lot of posts about it, but I don't want to upload a URL image to the library, I already have the image in the library and its IP. How can I use it with wp_insert_post?
0
votes
1answer
103 views

Allow unfiltered HTML for not logged in users when saving a post

I'm using this code: $var1 = $_GET["t1s2ninput"]; $var2 = $_GET["t1s2pinput"]; $new_post = array ( 'post_title' => 'Title <dl class="variation"> <dt>Variation: </dt> ...
1
vote
0answers
273 views

How to set featured image in wp_insert_post

I have a register form with upload field and when the user registers i create a new post. I need to have the uploaded picture on the featured image of the post. I have see something like this but i ...
0
votes
1answer
152 views

Can wp_insert_post_data filter be used to save custom field data?

I have custom field data that I would like to modify on its way to the database. wp_insert_post_data filter seems to be the closest thing I can find to achieving this. I dumped the $data and $postarr ...
0
votes
1answer
62 views

How can I get some of a posts meta data whilst it is still inserting?

I'm trying to make a function where a child post of a certain post type inherits the same title and slug as its parent. I'm using WP Types to define my post types and their relationships. But I'm ...
-1
votes
1answer
61 views

Use of wp_insert_post and parameters

I've JUST started using WordPress..i'm trying to add posts to Wordpress using php and i came across this piece of code: // Create post object $my_post = array( 'post_title' => 'My post', ...
0
votes
1answer
275 views

WooCommerce wp_insert_post action firing on every save

function initial_product_data ( $post_id ) { // lets get out of here if this is not a new product if ( 'product' != $_POST['post_type'] ) return; // make sure the post isn't automagically ...