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
2answers
602 views

generate unique slug while inserting post

How can i create unique slug while inserting a new post.. I know i can query posts and compare the records to create unique slug but I want to insert a post with unique slug at the same time. Lets ...
0
votes
0answers
19 views

Call to a member function insert()

I did a POST form and try to sign in to the Wordpress database is showing this error. Fatal error: Call to a member function insert() on a non-object in C:\wamp\www\teste\wp-content\themes\...
1
vote
3answers
322 views

save_post action to include wp_insert_post_data filter, gathering meta field info & prevent infinite loop

Im trying to change the title of a post, but I want to include info from a meta field, the value of which isn't saved to the database until after the posts has already been saved. Other than this one ...
0
votes
1answer
489 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 ...
3
votes
2answers
187 views

Can we have a post without a slug?

When I insert a post I've found that there is a slow call to wp_unique_post_slug from within insert_post (In the database I'm using to test there is 155,000 posts - live would have considerably more). ...
0
votes
2answers
958 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
499 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 ...
0
votes
1answer
2k 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 ...
1
vote
1answer
28 views

Can't get wp_insert_post to work

I'm trying to code a loop that will post articles from a SQL database. However, whenever I try to load the page I get a 500 error and nothing is showing up in the error logs. Code: <?php define('...
1
vote
1answer
729 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
2k views

How to insert category and subcategory using 'wp_insert_post' function?

How would be the array, to insert a post category and subcategory? Thanks.
0
votes
1answer
2k 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 = $wpdb->...
1
vote
1answer
516 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 ...
3
votes
1answer
592 views

wp_insert_post extremely slow on big table, direct query very fast

My posts table is about 600K, and I don't consider this big at all. Anyway wp_insert_post is becoming very slow. I am trying to import a huge list of hotel information into Posts. The list is about ...
0
votes
2answers
671 views

Add action to create new post after wp_insert_post fires? Think it's creating an infitnite loop

I need to take the post meta from a post, and create a custom post type post. I'm using the code below but think it's creating an infinite loop. When wp_insert_post fires I have create_cptpost ...
3
votes
1answer
94 views

Why is there both a save_post and wp_insert_post action?

I just realised that in wp-includes/post.php (source), at the end of wp_insert_post(), both the save_post and wp_insert_post actions are called one after the other, with the exact same parameters: ...
0
votes
0answers
8 views

Create a post on registration with title include user first name

I use this code for create a post (-type) on user registeration: function create_new_user_posts($user_id){ $userinfo = get_userdata($user_id); if (!$user_id>0) return; $my_bio_post = ...
0
votes
1answer
27 views

Programatically inserted posts not showing in Posts Table

I'm trying to insert a custom post through a form. It's a brief post, most content are custom meta fields updated with add_post_meta. So far, post inserting is working fine, except for a detail. This ...
5
votes
3answers
8k views

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 ...
0
votes
1answer
48 views

Create Page With wp_insert_post() and AJAX

I've been trying to figure out how to create a post (or any custom post type) with wp_insert_post() and AJAX...so far to no avail. What I hope to achieve: Any user (not just logged in ones, I don'...
1
vote
1answer
3k views

wp_insert_post or wp_set_post_terms do not save taxonomy, but wp_set_post_terms does

I have a litlle problem. I have a custom taxonomy 'rodzaj' with value i.ex. obrazek. I use this code to add post: $postArray = array( 'post_status' => 'publish', '...
1
vote
1answer
3k 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
2answers
2k 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
1answer
26 views

Get original post ID after wp_insert_post

I have a plugin with several CPTs (we'll call them CPT-A, CPT-B, CPT-C, and CPT-D). All CPTs have custom fields. In CPT-D, the user is able to make a selection and assign a post in CPT-A, CPT-B, and ...
0
votes
1answer
557 views

upload images on front by user using form

I'm using a form on my website using wordpress to allow users to create posts. It works perfectly fine, I'm abble to assign the posts to a custom post type, add Advanced Custom Fields, content, tags......
1
vote
0answers
37 views

Attaching taxonomy data to taxonomy with wp_insert_post

By WP User Frontend I create a registeration form with some checkboxes, and use wp_insert_post and update_user_meta for create a new post (post type pavilion) on user registration.I want when checked ...
1
vote
1answer
81 views

keep wp_insert_post from adding duplicates

I have been struggling to import posts from an some json data. The problem is that wp_insert_post() is adding multiple versions of the posts. I was previously checking if the post existed by checking ...
3
votes
3answers
7k views

Check if Post Title exists, Insert post if doesn't, Add Incremental # to Meta if does

I already have a function where a user submits a form and creates a custom post... <?php $postTitle = $_POST['post_title']; $submit = $_POST['submit']; if(isset($submit)){ global $user_ID; ...
2
votes
1answer
1k views

Issue with wp_insert_post and post_content field error Could not update post in the database

I'm having issues creating an import / caching script to be used within a WordPress site. This feed comes from a single text file that is then parsed and returned as an array. When running through ...
0
votes
0answers
16 views

Hook and prevent certain posts from being imported

0 down vote favorite I'm using WP ALL Import to import thousands of posts from a custom XML file. I filter it the best I can with XPath, but some conditions have to be done in PHP. How can I hook ...
1
vote
1answer
403 views

create parent post using wp_insert_post

how can i create php function where i can create a post in one custom post type also create a child post type, i have already create a parent post type, i.e post type "a = car" post type "b = user" ...
0
votes
0answers
50 views

Front end post submit with custom taxonomy and category

On my website i'm buildng a front end post publishing based on this article. All my posts have both category and a custom taxonomy. The problem is that I can't find a way to save both default ...
0
votes
1answer
23 views

Help to upload post attachments from Ajax

My problem is that I cannot upload post attachments from a frontend form. I send data through AJAX to my php files containing functions. Let me be clear: everything is working great, the post is ...
1
vote
0answers
70 views

Frontend Post with JQuery AJAX to Php Issue

My problem is the following. I'm trying to make users publish custom post_type by frontend through a form like this: <form id="msform" enctype="multipart/form-data"> <fieldset id="...
0
votes
2answers
86 views

Get post ID from wp_insert_post()

$new_post = array( 'post_title' => $title, 'post_content' => $description, 'post_category' => array($...
0
votes
1answer
79 views

can't edit post_modified in wp_insert_post (bug?)

It smelss like a bug but adding the post_modified in wp_insert_post isn't working: $wp_test = array( 'post_title' => 'test', 'post_content' => 'test', 'post_status' =>...
0
votes
1answer
22 views

Is it possible to get a shortcode generated by a plugin, then, using a function, create a new post using that shortcode?

I am planning to purchase a plugin that allows users to create polls and then embed them via shortcode into posts. It looks like a great plugin all around; however, the functionality I would like is ...
2
votes
1answer
2k views

Define page template in wp_insert_post

How can I set which page template this page, created using wp_insert_post, uses? I want it to use template-blog.php This is my current function; add_action( 'admin_init', 'mytheme_admin_init' ); ...
0
votes
0answers
20 views

Where to direct the “action” of a form with a custom plugin to upload a post?

I'm trying to create my very first very own plugin to upload posts into WordPress. I'm learning by looking at another post uploader plugin out there, but I was really confused about the action of the ...
0
votes
1answer
116 views

Fatal error: Call to undefined function wp_insert_post()

So I have a form that has makes the action jump to another php page. There my php code tries to upload a post. I get the following error: Fatal error: Call to undefined function wp_insert_post() ...
1
vote
1answer
388 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' =>...
9
votes
2answers
127 views

Is there a downside of using wp_defer_term_counting?

I have a WordPress database with over 2 million posts. Whenever I insert a new post I have to call wp_set_object_terms which takes over two seconds to execute. I came across this post that recommends ...
0
votes
0answers
62 views

wp_insert_post fatal memory error

I am trying to insert a single post via an ajax function with wp_insert_post and I get the following error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 ...
31
votes
5answers
51k 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
30 views

wp_insert_post - Categories in checkboxes

I'm having some problems trying to attach multiple categories on my submit form. I have this: <p> <label> <input type="checkbox" name="categorias" value="Wood Frame"> Wood ...
0
votes
1answer
425 views

wp_insert_post add meta_input

In the documentation of wp_insert_post there is a changelog on half of the page which says the following: Since: WordPress 4.4.0 A 'meta_input' array can now be passed to $postarr to add post ...
0
votes
1answer
15 views

Importing custom DB table entries as posts with Categories

I'm using the following code to import all entries within a custom DB table as posts. The function fires from an init hook. All taxonomies are created, and all entries from the DB are imported, ...
1
vote
1answer
150 views

Update post meta does not serialize array

For some reason my update_post_meta() function does not accept an array. Normally the function serializes the array by itself, but now I need to do this by myself, otherwise it does not update. Could ...
1
vote
4answers
12k views

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'])) {...
7
votes
1answer
909 views

What is “meta_input” parameter in wp_insert_post() used for?

I am inserting some post into wordpress using the function wp_insert_post(). I want to insert some custom fields on each post and reading the documentation I though the meta_info parameter was used ...