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
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, ...
1
vote
1answer
102 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
50 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
788 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
750 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
367 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
185 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
554 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 ?
0
votes
1answer
252 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
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 ...
4
votes
1answer
955 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
225 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
3k 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
831 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
742 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, ...
3
votes
2answers
469 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
268 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
277 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"; ...
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 ...
0
votes
1answer
417 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
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.
1
vote
1answer
613 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
437 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
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
409 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
119 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
130 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
5k 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
254 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
305 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
355 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 ...
0
votes
1answer
134 views

Somehow adding to “Insert Into URL” posts are contradicting each other

I added a second upload image ( doc_thumb_box ). They both work perfectly independent of each other. But when the second one is added, the first one (doc_uri_box ) no longer pastes the value of the ...
0
votes
1answer
184 views

Is this the correct way to add post-slug input field?

I added slug input field in my custom post type and allow users to edit it at front end. Then, when insert post, I use this: $wp_insert_post_args = array( 'post_status' => 'publish', ...
0
votes
1answer
318 views

Conditional wp_mail statement on post

I am currently posting from the front end using a similar model as http://voodoopress.com/2011/03/review-of-posting-from-front-end-form/. I want to send an email to certain addresses based on the ...
2
votes
1answer
1k views

save_post + insert_post = infinite loop

I'm trying to automatically create a new post when a post containing a certain custom field is saved - hooking an insert_post function into save_post. This generates an infinite loop. I found some ...
2
votes
1answer
724 views

How many 'wp_insert_post' calls can be performed in one shot, in a very long 'for' loop?

I'm working on a plugin which has bulk post inserts using a spreadsheet. This spreadsheet can have multiple thousand rows, each row corresponding to a post. I'm parsing this spreadsheet, looping over ...
0
votes
3answers
832 views

How to prevent duplicate posts with wp_insert_post on single.php?

I'm getting a really strange bug (WP 3.1.3). My goal is to have users create a new post simply by landing on a single post. In order to make that happen, I have the following code in my single.php: ...
0
votes
3answers
501 views

Trying to save custom post type from frontend partially working

I've created the following custom post type (lugares means places) with a custom taxonomy of tacos and it works fine form the backend: /** * Custom post-type lugares **/ add_action('init', ...
0
votes
2answers
381 views

WP Cron is “half-failing” to insert posts

I built a plugin for my company, which basically goes to tube sites, scrapes them for content, and posts them automatically in whatever state is defined (publish, draft, future, etc). Now, everything ...
1
vote
1answer
539 views

update_post_meta, xml parser

I'm hitting the wall for nearly two hours now, trying to figure this out. Here is the thing' I have made a xml parser to read xml file and add posts (with content) from xml: $ch = curl_init( ...
0
votes
2answers
283 views

Using wp_insert_post with WP Network in a cron script

I have network of sites, and I need to import data into them via a cron job. Obviously wp_insert_post is meaningless in this case, since i'm not in a blog...i'm in a cron script. I also read that ...
1
vote
2answers
4k views

How to use wp_insert_post to update meta box?

I'm trying to use wp_insert_post to create a front-end submission form so visitors can create a post AND update the meta box fields of that post -- not the custom fields. For example, when I use the ...
2
votes
2answers
841 views

wordpress sanitize array?

I have a custom post form that sends data to a page which uses wp_insert_post to create a post. I can easily sanitize most data, but I have some troubles with my tags, I retrieve in an array: $tags = ...
0
votes
1answer
181 views

How can I correctly redirect user to the submitted post and define a template for each new post in Wordpress?

What I want to do is to create a simple front-end post submit form, for every different type of post I will include in my Wordpress app. For example there will be articles, events, quick messages and ...