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

2
votes
1answer
362 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 ...
1
vote
1answer
482 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 ...
1
vote
1answer
54 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
502 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 ...
0
votes
1answer
21 views

php wp_insert data on front using a form

I'm using a form on my website to allow user to create posts on my wordpress admin. It works fine, but I have an issue, I don't get the tags meta inside my admin. here is my php code : <?php ...
0
votes
1answer
19 views

Add image to post from external URL

I'm doing a plugin that can retrieve media from external APIs, and when I click on it (on the admin), it insert a new post with the media, its caption, etc. So, now, I'm inserting a new post on click ...
0
votes
1answer
68 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
360 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
74 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
1answer
28 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
92 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
254 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
76 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
1answer
45 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
1answer
130 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
1answer
114 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( ...
1
vote
0answers
60 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 ...
1
vote
0answers
528 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 ...
1
vote
0answers
299 views

wp_insert_post - How do I prevent incremental numbers on child pages?

I'm using wp_insert_post to dynamically generate child pages for a given page using a predefined array of values. The goal is to give each child page the same slug. For example, clicking "Generate ...
1
vote
0answers
227 views

Posts added with wp_insert_post are moved to trash automatically

I've got a script that loops through some data and automatically creates some posts. foreach($data['title'] as $title) { $my_post = array( 'post_title' => $title, 'post_content' ...
0
votes
0answers
14 views

Cannot save json in wp_insert_post

This is my code. $offer_name doesn't get saved. $obj = json_decode($result, true); $i = 0; foreach($obj['response'] as $item) { for($i=0;$i<=$item['count'];$i++) { $offer_name= ...
0
votes
0answers
20 views

wordpress form processing to custom post type not working

I'm trying to insert a custom post type for a multiple image upload form. The below code is the form processing. The page is blank when i submit the form. Where did i go wrong? <?php ...
0
votes
0answers
11 views

How to insert new user to database when post created

I'm trying to use wp_insert_post_data filter to insert a new user into the database when a new post is created. This is the code I have function post_add_user( $data , $postarr ) { $postid ...
0
votes
0answers
50 views

Create post using Ajax

I want to create post using Ajax . I had followed the process from Insert Post using Ajax But I couldn't make it work. Here is what I did. Please see what I did wrong as I am just a learner. EDIT ...
0
votes
0answers
17 views

wp_insert_post insert a post but return 0

I am trying to insert a page of a theme with after_switch_theme hook .Now when I set the page_template then it insert the post but return 0. Is there a way to insert a page with specifying a template ...
0
votes
0answers
26 views

Why doesn't wp_insert_post script works?

$user_id = $_POST['post_user']; $get_user = get_user_by('id', $user_id); $post_title = $_POST['post_company_name']; $post_hidden_section = $_POST['post_hidden_section']; $post_hidden_category = ...
0
votes
0answers
18 views

wp_insert_post keeps returning a post_parent id

I'm doing this: $postarr = array( 'post_status' => 'publish', 'post_type' => 'attachment', 'post_title' => $name, 'post_content' => '', 'post_author' => 2 ); $post_id = ...
0
votes
0answers
14 views

adding a log row log table, when the draft post publish

i wrote some codes, about wpdb update query. but update_post meta works fine but, wpdb update query doesn't. where am i wrong ? here is the code ; add_action('publish_post', ...
0
votes
0answers
46 views

Get Custom Field Value of a $post_id on wp_insert_post Action in functions.php

I have this code in the functions.php file which emails the post content to the admin every time a pending post is added to the database: function send_email_on_pending_post_creation( $post_id ){ ...
0
votes
0answers
34 views

Inconsistent post order using wp_insert_post

I am retrieving a consequent (~4000) number of posts from a database that I want to save to my WordPress database. I am inserting them this way: include("wp-config.php"); $con = ...
0
votes
0answers
35 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 ...
0
votes
0answers
50 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
0answers
31 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" /> ...
0
votes
0answers
43 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
51 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
66 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
0answers
60 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
0answers
37 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
0answers
61 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
75 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
0answers
50 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
0answers
92 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
0answers
22 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
0answers
34 views

Want a form to appear in a post via wp_insert_post, form tags appear, fields don't

I use wp_insert_post to import external data in WP3.8. Part of the post_content field is a small form, see below. $content="<table><tbody><tr>"; $content.="<td><form ...
0
votes
0answers
74 views

WP Infinite loop

It is not working. add_action( 'save_post', 'jdev_save_custom_meta_box', 13, 2 ); function jdev_save_custom_meta_box(){ global $post; // Get our form field if( $_POST ) : if ( ...
0
votes
0answers
251 views

Prevent Duplicate Attachment When Using wp_insert_post

I am trying to use wp_insert_attachment while using wp_insert_post. It's successfully creating the post and attachment. It have no problem if I only use the wp_insert_post function, but when I ...
0
votes
0answers
225 views

wp_insert_post and title not utf8 inserts with empty title?

I'm using wp_insert_post I loop over a text file one row at a time and for each row I create a post. The text is set as the `post_title', for text that is not utf8 the post inserts but with an empty ...
0
votes
0answers
105 views

Update fields with post object and custom tax with wp_insert_post

Updated Post 'update_field' Function is Acf Plugin $supplier_one = 'my supplier'; $supplier_two = 'my supplier TWO'; $post_id_one = 555; $post_id_two = 556; update_field('suppliers', $supplier_one, ...
0
votes
0answers
157 views

Getting error when using wp_insert_post()

When I use wp_insert_post() I get a white page that says "Are you sure you want to do this?". I get no PHP errors. I am using this outside of wordpress and have wp-load.php as well as ...
0
votes
0answers
56 views

Omitted Content After Post-Publish Insertion

I have a string that contains $thehtml but whenever I insert it manually into a custom post it appears that wordpress alters/strips down the html.... I've already tested/outputted $thehtml string in a ...