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
1answer
142 views

HTML Entities in Post Title

I'm inserting posts into wordpress using a script which is loaded through CRON. Before inserting each post I am checking whether the post with the same title exists or not. Below is the snippet I'm ...
1
vote
1answer
210 views

wp_insert_post not updating custom taxonomy selected if logged in as a subscriber

Here is my Code, it works fine When i try to post data from front end if Logged in as admin, but if i logged in as a subscriber code works fine but it is not inserting the taxonomy term i select, here ...
0
votes
1answer
101 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 ...
2
votes
2answers
1k views

Adding post thumbnail in programatically inserted post

I want to insert post programatically so here is the code to add one: global $user_ID; $new_post = array( 'post_title' => 'My New Post', 'post_content' => 'Lorem ipsum dolor sit ...
1
vote
1answer
109 views

How To Disable Comments On New Page

I am writing a plugin that upon activation, it creates a few new pages. On these pages, I want to disable the comments option. I am adding the new pages via the code below: $page['post_type'] = ...
0
votes
2answers
58 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
157 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
296 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
281 views

Alternative to new_to_publish Hook for Custom Statuses

I am looking for the right hook to use for sending out an email notice when a post is inserted. However, I am using custom statuses (in this case 'holding') which doesn't seem to get hit with the ...
1
vote
1answer
1k views

insert post & Upload post thumbnail from the front end using ajax

i have searched & searched for an explenation and have found some answers that seem to be working for other people on this topics but i havent been able to get working. This is my "form" <div ...
0
votes
1answer
131 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 ...
1
vote
1answer
242 views

Inserting post, thumnail and custom fields with wp_insert_post

I just want to add custom post, a thumbnail of it and custom fields. Here is my code what I am try is to add post, thumbnail and one custom field. But I not getting the idea how to upload the ...
2
votes
1answer
845 views

Inserting Hundreds of Thousands of Posts at Once

I have a project in which I create an array of 200k+ lines w/ 25 fields that run the wp_insert_post and update_post_meta. To start it processes pretty fast the slows down a lot after 10k records or ...
1
vote
0answers
245 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 ...
0
votes
1answer
142 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
531 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 ...
2
votes
2answers
203 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 ...
4
votes
3answers
593 views

Running WP Cron on specific local time

The scenario is to run insert_post function every midnight (00:00) of local time. Must run daily on weekday. function add_daily_task(){ if((date('l', time()) != 'Saturday') || (date('l', time()) ...
1
vote
1answer
395 views

After wp_insert_post(), date_i18n() and date() outputs are adjusted to GMT

I am having a very peculiar issue on a customer's server (vps). The code below works just fine on my servers. Basically, a specific unix timestamp is formatted correctly and as soon as ...
0
votes
1answer
577 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
1answer
2k views

How to use `wp_insert_user` & `wp_insert_post` simultaneously without `headers already sent` error?

I'm creating a front end posting form using wp_insert_post that asks a user for three basic fields: their first and last name and their email address. If the user is logged in I pre-populate the text ...
0
votes
2answers
162 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, ...
1
vote
1answer
2k 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
99 views

Frontend tag edit/submit form

I would like to have a separate page to submit/edit tags. Any user can edit or submit tags. But it should be published only after admin approval. Is there any function available like ...
1
vote
1answer
46 views

Add file while inserting post

Is it possible while adding post through wp_insert_post also upload images to this post from url.
1
vote
1answer
438 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 ...
2
votes
2answers
176 views

Is there a faster way than wp_insert_post to add content to a blog

I've written a plugin which retrieves an xml file, parses and creates a series of short posts from the content. Although each post is very short (sometimes just a single sentence, never more than a ...
0
votes
1answer
482 views

Add a default meta_value to new posts

I have a page template that allows users to create and update posts from the front end. I also am using 2 plugins, 1 that allows the user to rate posts from 1-5 stars and another that allows them to ...
0
votes
1answer
1k views

wp_insert_post disable HTML filter

I have input value "<iframe>....</iframe>" (param 'post_content'). When i execute wp_insert_post, function cut off my tag. How to disable HTML filter in wp_insert_post ?
1
vote
1answer
311 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
161 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 ...
1
vote
0answers
189 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' ...
2
votes
1answer
730 views

How do I Import an RSS feed as Wordpress posts without duplicates?

I have an XML feed url I am now using this code to create new Custom Post Type Posts from an rss feed in my functions.php file: /* | ...
0
votes
2answers
339 views

Is it possible to add posts and images (auto resize) for custom post types with a script?

I have a specific need to import many post with featured images into a custom post type. The issue is, I need this to be a script because it runs off of another system that collects all the data. I ...
2
votes
1answer
592 views

Programmatically insert hierarchical terms & set terms for post causes glitch? [duplicate]

I am inserting an array of terms into my custom taxonomy programmatically. Some terms have parents/children. After each term has been entered, I then insert an array of posts into my custom post type. ...
1
vote
0answers
243 views

Insert new term during new post creation

i am currently working on a snippet to insert a new post dynamically (it's a custom post type). During this new post creation i need to insert terms in custom taxonomies associated to the custom post ...
0
votes
1answer
820 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
250 views

add_menu_page Callback Function: Skip page content?

I want to have a menu item that will, on-click, add a page with certain arguments. In it's simplicity, I have: function av_subscribe_create_menu(){ // Create top-level menu add_menu_page( 'Add ...
1
vote
0answers
276 views

Wp_Insert_Post: Do not insert if the title exists [duplicate]

i've made a simple code here to fetch and insert the last news from a feed Rss: <?php // Get RSS Feed(s) include_once"wp-config.php"; include_once"wp-load.php"; ...
0
votes
2answers
3k 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; ...
0
votes
1answer
387 views

wp_insert_post alternatives for faster process

I'm using wp_insert_post to generate posts for my site. Initially, everything works fine and it was very fast. When the number of posts accummulated to about 3000, it became very slow and now i almost ...
0
votes
1answer
681 views

preventing the duplicate wp_insert_post

Right of the bat, let me say that this is not the same question as I posted the other day ( that is duplicate posts when trying to update a post using the wp_insert_post. ) Cause, in that question, ...
4
votes
1answer
869 views

wp_insert_post incorrectly escapes HTML comments when they include tags

I'm working on writing a script to import data from a custom CMS into Wordpress. As part of this, I need to import the post content exactly, without modifying anything. However, some of the posts ...
0
votes
1answer
208 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.
1
vote
1answer
563 views

duplicate posts when trying to update a post using the wp_insert_post.

On an empty wordpress database, I insert one sample post using the wp_insert_post. Since it's an empty database, the first post I add ends up with id 1. And I check that in the wp_posts, everything ...
3
votes
1answer
860 views

Create posts on user registration

How can I create let say 3 posts after the user finish the registration ? The ideal outcome would be to create 3 posts using the user as the author of the posts and with some pre-defined values. ...
6
votes
1answer
3k views

wp set object terms vs wp set post terms

Examining the following sample code snippet from the WP codex, $post = array( 'ID' => [ <post id> ] //Are you updating an existing post? 'post_author' => [ <user ID> ] //The ...
2
votes
2answers
400 views

Prevent empty Post Title on form submit via front end post (wp_insert_post_)

I am creating a post from the front end using (shortened for brevity); if (empty($_POST['my_title'])){ echo 'error: please insert a title'; } else { $title = $_POST['my_title']; } ...
1
vote
1answer
175 views

post_content sanitization / transformation process

What kind of transformation does the post_content go thru when wp_insert_post inserts a post_content into wp_posts programmatically? I'd like to be aware of this before I process 50000 recs into ...