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
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
17 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 ...
1
vote
2answers
520 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 ...
5
votes
3answers
7k 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
0answers
14 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\...
0
votes
1answer
27 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
938 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
492 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
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
24 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
1k 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
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->...
3
votes
1answer
566 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
1answer
545 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......
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.
1
vote
1answer
722 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 ...
1
vote
1answer
29 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
513 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
1answer
57 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
908 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
15 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
385 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
32 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
20 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 ...
0
votes
0answers
43 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
68 views

Get post ID from wp_insert_post()

$new_post = array( 'post_title' => $title, 'post_content' => $description, 'post_category' => array($...
0
votes
1answer
56 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
21 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
19 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
70 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
371 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
114 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
56 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
50k 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
25 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
332 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
14 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
130 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
11k 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
743 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 ...
0
votes
0answers
68 views

Getting blank (no title) posts submitted when using wp_insert_post()

I have users submitting post to the wordpress admin. For the most part this works but sometimes I will get post submitted that are blank and (no title) is the title. I cant seem to find out why this ...
0
votes
2answers
83 views

Get Post ID after front end post submission

I can't get the published post ID, i'm using a front end custom form. When the submit button is clicked site is re directed to a different page. Now, i can't get the just published post ID using: ...
0
votes
1answer
92 views

Where to call wp_insert_user() and wp_insert_post() from?

I'm trying to perform a batch insertion of multiple users and posts using the wp_insert_user() and wp_insert_post() functions. The problem is, I can't find any clear instructions as to where I should ...
0
votes
2answers
52 views

oEmbded with wp_insert_post() [embedly]

I try to add articles via wp_insert_post but as it seems the oEmbed function of Wordpress doesn't work properly. I work with embedly as you can embed any website. I realized that the oEmbed ...
0
votes
0answers
87 views

Using wp_insert_post() and wp_insert_attachment() at the same time

I am working on migrate blog posts, which are more than 1000 posts, from an old custom database website to wordpress. After formatted each post with php array, I am testing how to migrate them to ...
4
votes
1answer
176 views

See error message from wp_insert_post function?

I'm using wp_insert_post function to insert a new post: $result = wp_insert_post(array("post_title"=>"test1"), true); When I echo the result of the function, I get the number 335. How can I see ...