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
1answer
103 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
66 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
0answers
52 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
1answer
37 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
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
1answer
109 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
0answers
52 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
64 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
1answer
109 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( ...
0
votes
0answers
43 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
67 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
148 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
61 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
146 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
53 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
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
1answer
28 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
1answer
69 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
441 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
377 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
0answers
33 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
67 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 ...
0
votes
0answers
72 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
24 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
60 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
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
0answers
234 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
1answer
148 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
199 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
95 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
134 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
1answer
133 views

Insert a Woocomerce product in specific product category

I'm a bit new to Woocomerce plugin and have a problem. I need to create products from code not from admin page. Probably I will insert them with wp_insert_post( $product ). The problem is I don't ...
0
votes
1answer
107 views

Set post_parent from URL params in post-new.php

I'm trying to create a set of buttons on wordpress Page post types that allow the end user to create a new page that is a sibling (same parent page) or a child page of the current page. In order to ...
0
votes
1answer
337 views

Front end posting

This source works with image upload. Without image upload, it works, but 'redirect' doesn't work. What should I do?? Any suggestions to what the problem might be? if( 'POST' == ...
0
votes
1answer
73 views

install.php Custom Taxonomy Term not being added to custom post

So I am stuck on this problem that I am facing when creating a custom taxonomy term in a install.php file. So I am running a WP multisite, and upon new blog creations, I am trying to auto create ...
0
votes
1answer
109 views

Post content not showing some content

I'm inserting posts by wp_insert_post function. It works like first a post is created to get its id then an image is attached to that post id. I attach images by media sideload function. Here is the ...
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 ...
0
votes
2answers
61 views

Add Page With Parent ID

I am writing a plugin that upon activation creates a set of pages. The first page that I create I want to be the parent of the rest of the pages that are added. For some reason, this is not working. ...
0
votes
1answer
170 views

Import Dummy Content and Post Thumbnails

I am setting up a small dummy content plugin. What I would like to do is import several posts using wp_insert_post. Then I would like to import several images using wp_insert_attachment and then ...
0
votes
2answers
313 views

Yet another wp_insert_post infinite loop. What is wrong?

I am writing a plugin that enables subscribed users to submit posts of a custom type, and I am trying to implement this feature via shortcodes. Now the problem is that instead of inserting one post, ...
0
votes
1answer
159 views

wp_insert_post memory consumption

I'm using wp_insert_post in a loop to insert 500 posts in a new WP install. It works quickly, and memory usage is from 25M to 28M. The next run of a second batch of 500 posts, takes the memory from ...
0
votes
1answer
144 views

wordpress apply filters and is singular()

I'd like to know whether anybody has heard of , or created a workaround to the following problem: let's say there is a plugin which has code like this, add_filter('the_content'.'some_func'); ...
0
votes
1answer
617 views

Inserting post_id into guid before wp_insert_post

I would like to insert data into the wp_posts table with the inserted post_id in the 'guid' for a record that doesn't already exist. Below is the closest I've gotten but this doesn't work ...
0
votes
1answer
760 views

How to update post parent?

I have an array of image id's and i want assign them to the specific post: foreach ($image_ids as $image_id) var_dump(wp_insert_post(array('ID' => $image_id, 'post_parent' => ...
0
votes
2answers
186 views

Upload image and assign it's id to post

At the moment i am working on database conversation script from other cms to Wordpress and faced one problem: I have a list of images, so i need to upload it to Wordpress, after it receive new link, ...
0
votes
1answer
174 views

Insert new post for each user infinite loop error

I wrote this little function to automatically create a post for every user of the blog but it creates an infinite loop (I disabled it to stop it creating new posts). I'm not very skilled in php, I ...
0
votes
1answer
883 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
217 views

Fire a hook programmatically

Is it possible to fire a wordpress hook programmatically? Specifically I'd like to have control of wp-insert-post.
0
votes
1answer
1k views

wp_insert_post with POST data

I found some code on this site for wp_insert_post and I got it working. I did find the post in the category where I would expect it to be. Then I changed the code example to include information from ...
0
votes
1answer
1k views

Cant get front end form to post to wordpress

Long time lurker, first time poster, and big time PHP noob. Apologies if my question is a little vague, but i have the code below and I know im doing some sort of schoolboy error but it just wont ...