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

3
votes
1answer
82 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
20 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 ...
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
28 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'...
0
votes
1answer
25 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 ...
1
vote
1answer
30 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
59 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 ...
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 ...
0
votes
0answers
35 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
44 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
70 views

Get post ID from wp_insert_post()

$new_post = array( 'post_title' => $title, 'post_content' => $description, 'post_category' => array($...
0
votes
1answer
60 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 ...
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
78 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() ...
9
votes
2answers
119 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
57 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 ...
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
346 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, ...
7
votes
1answer
772 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
75 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 ...
1
vote
1answer
139 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 ...
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
96 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
54 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
88 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
187 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 ...
0
votes
1answer
34 views

Getting duplicate page when activating my plugin

I am creating a plugin in which I need to create a dynamic page and assign a template to it. I have created it using the code below: function gallerypage() { global $wpdb; $check_page = $...
0
votes
2answers
63 views

PHP - Multiple variables in insert post array

I am currently creating a post programmatically, with the wp_insert_post function but am having some difficulties when adding two variables into the content part of the array. I would like to add $...
1
vote
2answers
222 views

wp_insert_post creates multiple pages

I have a function in functions.php which automatically generates a page. It doesn't check to see if there is already a page with the same title at the moment. The function is started with: ...
2
votes
2answers
121 views

Automatically insert php function into post $the_content

I am trying to have 2 php functions automatically inserted in every post for my CPT. The problem I am having is that even though I've found a way to add text, Im not sure how to add the php functions ...
0
votes
0answers
44 views

Use return values on AJAX call to async-upload.php via Add Media

I noticed, every time I upload images via Add Media button on front-end. It makes AJAX request to async-upload.php and returns attachment file information. On above image, I have 3 images uploaded ...
0
votes
0answers
57 views

How to update post_parent on images uploaded via Add Media button from front-end

I'm working on a plugin that will allow registered users to post content from front-end. I added WordPress default Add Media button on TinyMCE and noticed all the images uploaded via Add Media get ...
1
vote
1answer
103 views

tax_input not working wp_insert_post

I am using wp_insert_post and all the fields are working except tax_input is working. Is there something wrong with my code? $customtax = array( 'product_link' => $link, 'product_price' => $...
0
votes
1answer
130 views

Create Post Using Form on WP Dashboard

As always, I have unique situations and client requests. I am working on a custom dashboard widget that will include a form to register for an event. Once the form is submitted, it will generate a ...
1
vote
0answers
329 views

Upload featured image from front end using media-upload.php

I'm trying to use admin/upload.php to upload featured image from front end form. All I have to do is put below code in the front end form <div id="postimagediv" class="postbox "> <div ...
0
votes
1answer
398 views

How to handle dynamic form data with repeating fields?

I'm attempting to create a form with duplicatable sections for a listing site. It should work like this: Start with one listing form -> Fill out the form Click "add another" and another duplicate ...
0
votes
0answers
90 views

How to add featured image on front end form?

I'm working on my first WordPress plug-in for front end posting where signed in users can post and manage their articles on front end. I'm pretty close to be done but can't find a way to add Featured ...
0
votes
1answer
224 views

wp_insert_post() post_author and return post_id are not working

This is my first time creating a plugin for WordPress and I'm trying to create a plugin for Front-end form for logged in users. So far, the front-end form shows up on a page with a shortcode [write-...
2
votes
1answer
178 views

XMLRPC Avoid duplicate content

I want to avoid duplicate post content via xmlrpc. So: if post exists nothing happens... . if does not exists data insertion occurs... . The method for checking would be post title or post ...
0
votes
1answer
44 views

Wrote a WP Cron Plugin and it triggers a fatal error upon activation

I'm writing a WP Plugin for one of my sites that hooks into a public API to get app data and save that within Wordpress to allow for WP to be able to search & filter the data based on new ...
2
votes
2answers
59 views

Replace string with post_name on sidebar

I'd like to replace all {POST_NAME} 's from my text-widgets on single.php sidebar. I'm thinking of something like this global $post; $POST_NAME= $post->post_name; $sidebar = preg_replace('/\{(...
0
votes
1answer
191 views

Update post_meta post_name with the post ID from wp_insert_post after user register

I'm creating a function that creates a page for a user when they register. The post created sits within a certain category. These are standard posts NOT custom post types. After the post is created I ...
0
votes
0answers
102 views

wp_insert_term or wp_set_object_terms not working in register_activation_hook?

I am creating a couple of CPTs and assigning a term to these posts. The posts are being created properly, but the term isn't being assigned to the posts. I tried using tax_input, wp_set_object_terms. ...
0
votes
1answer
60 views

Front end post submissions do not get submitted in the category

If I submit the post after choosing a category the post doesnt get submitted and instead it takes me to the category page i have selected.However if i delete the fieldset "category" and fill the form ...
0
votes
0answers
112 views

How to update posts via PHP in wordpress

I need to do the exact same what "update" button in the WP Backend does, but with PHP (and I know it has been asked 10'000 times, but the situation isn't that trivial :( ) wp_update_post should be ...
2
votes
1answer
923 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 ...