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
2answers
19 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
2answers
750 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
407 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
0answers
10 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
47 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 ...
2
votes
2answers
183 views

wp_insert_post() Callback?

After I added a post by wp_insert_post(); Any callback after I added ? I need permalink of added post. I have idea only search by title and post-type (I use custom post-type in my case), But any ...
1
vote
1answer
35 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
26 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 = ...
1
vote
1answer
293 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 ...
0
votes
1answer
39 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
25 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
220 views

front end posting

this source works with upload image, if without image upload, it works but 'redirect' doesn't work. what should I do?? Please let me know.. many thanks! if( 'POST' == $_SERVER['REQUEST_METHOD'] ...
0
votes
1answer
32 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
35 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
59 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
24 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
16 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
19 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
63 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
19 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 ...
1
vote
1answer
99 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
39 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
60 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
21 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
66 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
51 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
80 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
44 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
38 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
131 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 ...
0
votes
1answer
46 views

wp_insert_post issue

I've got the following code in the 'functions.php' file of a wordpress theme $ppost_data = build_post( $pID, $pcontent, $pname, $ptitle, $pstatus, $ptype, $pset_comment_status ); ...
0
votes
1answer
121 views

Adding custom fields (post meta) before/during wp_insert_post()

Our code base has a ton of logic that executes as the post is inserted/created. However, some of that logic depends on custom post meta. The only way I know of to add post meta to a new post is like ...
1
vote
1answer
186 views

Creating a post from data returned from HTML form

I am trying to write a WordPress plugin and I have hit a bump. The Background: I have some data in a mySQL DB that I am using (each row has a unique ID and some other information I have added). I am ...
1
vote
1answer
345 views

advanced custom fields update_field for field type: Taxonomy

I need to insert a post via wp_insert_post and then add relevant post_meta - however, the WP admin has been customized with the excellent ACF. I know I can add_post_meta in this way: add_post_meta( ...
0
votes
1answer
157 views

post_date_gmt and post_date [duplicate]

I am inserting posts programmatically using wp_insert_post. A typical call would look like this: $news_item = array ( 'post_title' => $titleField, 'post_content' => ...
0
votes
0answers
21 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
1answer
229 views

Insert Post using Ajax

I'm using the following code to submit a form from a Wordpress page. <script type="text/javascript"> $j=jQuery.noConflict(); $j(document).ready(function(){ ...
0
votes
2answers
182 views

post_status => publish not working

I have a front end form that let users submit a post. This is how i store the data when a post is submitted : if ( isset( $_POST['submitted'] )) { $post_information = array( ...
0
votes
0answers
35 views

How to get media-button on front-end

I am using wp_insert_post to allow non-logged-in users to add post, and would like to have 'add-media' button as well on front-end. I tried wp_editor, but I don't want the text editor, just the ...
2
votes
3answers
696 views

How to prevent duplicate slugs for wp_insert_post?

I have a function that creates a page when I create a post (so as to construct parent-child relationship trees). I'm using the $title of the post to create the page and this also creates a duplicate ...
2
votes
1answer
49 views

Wordpress tax_input only if logged in

I am working on a wordpress plugin where a save lead data by forms in my website. When a user submits the form the following code will run so a post in post type "lead" will be added. Almost ...
0
votes
0answers
55 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
1answer
18 views

I need to dynamic insert post containing javascript from my other website?

I am trying to dynamicly add some content post (also containing some js), but the javascript part is filter out. I thought by using wp_set_current_user the js would be included. This is my main ...
0
votes
0answers
50 views

Insert custom post type with taxonomies

I am tryig to insert my custum post type with a specific taxonomies , but it doesn't work Here my Custum post type add_action( 'init', 'create_annonce' ); function create_annonce() { ...
0
votes
1answer
44 views

What is the right way to clean up $title before wp_insert_post?

I am using a function to insert some post data and i am having problems with the title/title - slug. The title is random selected from an array, some title have ?, ! or . (dots) I notice ...
0
votes
0answers
12 views

Post array not printing after post is published? [duplicate]

I'm using this function which displays the post array when I click Add new post. After the post has been published I do not see the array of the published post. What's wrong with the code? I've also ...
0
votes
1answer
51 views

Setting Post Date Returning “Notice: A non well formed numeric value encountered”

I am using wp_insert_post to create post. While executing that function, I also set post date to schedule the post publish date using some variables. Here is the part of my code: //Intervals ...
2
votes
3answers
1k 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
209 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
3answers
129 views

How do I insert a post with custom post type and relate it to a custom taxonomy?

I'm trying to figure out how to insert a new post. I have a custom post-type (course) that is related to a custom taxonomy (categorycourses). I've managed to insert a post with custom post type ...