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
124 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
192 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
712 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 ...
2
votes
1answer
553 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
votes
3answers
138 views

Programatically add a page in Wordpress

I am trying to add a page to WordPress programatically. I am using this code: function add_media_page(){ if(!(is_page('My New Post'))){ // Create post object $my_post = array( 'post_title' ...
1
vote
0answers
226 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
138 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
445 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 ...
1
vote
1answer
376 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
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
1answer
430 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
145 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
92 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
44 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
5answers
1k views

Insert Wordpress page via external (cron) script?

I'm trying to write a php script that I can run out of cron to create new Wordpress pages. Unfortunately, I can't find any documentation on how to do this. I'm using the WP scripts rather than ...
1
vote
2answers
581 views

Making sure wp term relationships records are unique

Which' WordPress function is used in programmatically associating the term taxonomy IDs with post IDs? And does that function have internal mechanisms to make sure no duplicate entries are allowed ...
1
vote
1answer
633 views

using $wpdb to insert a form into a post

I am wanting to take the following form, and use $wpdb to insert it into a post. I have tried reading the class reference page INSERT rows, but I don't really know what should be referenced. I am not ...
0
votes
2answers
324 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
2answers
166 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
386 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
960 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 ?
0
votes
1answer
222 views

wp_insert_post - duration

i try to import a custom DB to the WP DB with about 2000 rows (custom post type). the problem is that the insert by wp_insert_post takes about a second per insert. Is this normal ? Is there a ...
0
votes
1answer
149 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 ...
4
votes
1answer
796 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 ...
1
vote
0answers
175 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
4answers
2k views

wp_set_object_terms() Fails to Set Terms

Okay guys, here's the scenario. I'm am trying to setup a function that will automatically duplicate a post (when published) over to another post type. So, a regular blog post is published, and when ...
2
votes
1answer
651 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
1answer
608 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, ...
1
vote
0answers
227 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 ...
3
votes
1answer
747 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. ...
3
votes
2answers
438 views

wp_insert_post breaks rewrite rules

I'm using wp_insert_post to programmatically add content to a site. This works fine with posts, categories and tags, but not with pages. When I attempt to add a page (i.e. post with post_type=page), ...
1
vote
1answer
237 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
264 views

Wp_Insert_Post: Do not insert if the title exists

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"; ...
5
votes
1answer
2k 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 ...
0
votes
1answer
359 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
196 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
506 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 ...
2
votes
2answers
355 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']; } ...
0
votes
3answers
3k views

Prevent duplicate posts in wp_insert_post using custom fields

My source links are something linke this : http://sample.com/entertainment/default.aspx?tabid=2305&conid=102950 http://sample.com/entertainment/default.aspx?tabid=2418&conid=104330 ...
0
votes
2answers
2k views

how can I set the post author of a post I just created with php?

I'm using php to dynamically create a custom post, and I need the author to be someone other than the logged in user. I found this ...
0
votes
1answer
353 views

Deleting terms from the Wordpress wp terms table

what wp function do i use so that I can delete a term without worrying about the related tables such as wp term relationships and wp term taxonomy? Also if a post has a relationship to the deleted ...
-1
votes
1answer
111 views

The reverse of wp_insert_post

When you need to delete a post programmatically what wp function do you use so that if takes care of the wp_term_relations too?
0
votes
1answer
122 views

how to add datas in taxonomy to post with wp_insert_post

how to add datas in taxonomy to post with wp_insert_post this is my code but it is saved in my texonomy draft,why? i have given post_type=publish. $my_post = array( 'post_title' => ...
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 ...
1
vote
2answers
4k views

WP insert post and custom taxonomy

I have create a custom post type in my WordPress attached with a custom taxonomy. The post collect date from the from end of the web site by using wp_insert_post(). This is my Custom post ...
1
vote
0answers
225 views

wp_insert_post not completing when run via cron [closed]

I have created a plugin that accesses an XML feed that contains articles and saves the articles from that feed as posts. You can set a time interval for the plugin to run via WP cron and access the ...
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 ...
3
votes
1answer
2k views

When and Where to use wp_insert_post()

I'm building a function that creates a group of pages with a common parent ID. If I run wp_insert_post() on a parent ID twice, does the function create the pages twice while altering the slugs? Or am ...
1
vote
3answers
297 views

Is it possible to create a post using a metabox?

I am trying to create a post (well, in the end, multiple posts) from a metabox using the 'save_post' hook. I executed the script once, creating 3900 or so new posts before I crawled into posts.php and ...
3
votes
2answers
338 views

PHP/Manual use of images? - 2 Questions

I've made a quick PHP script/page that uses the wp_insert_post() function to insert a post directly. And this works great. The post I am manually adding has an image in it, so I firstly ...