The wp-insert-post tag has no wiki summary.
5
votes
1answer
1k 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 ...
4
votes
3answers
9k views
How do I set a featured image (thumbnail) by image URL when using wp_insert_post()?
While looking through the function reference entry for wp_insert_post(), I noticed that there's no parameter in the array it requires which will allow me to set the 'Featured Image' for a post, ...
4
votes
1answer
513 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 ...
3
votes
3answers
4k views
Attaching taxonomy data to post with wp_insert_post
I am implementing (trying) a front end posting system which shows taxonomy data in several dropdown select fields, each of the dropdowns is named by using the "name" $arg in wp_dropdown_categories.
...
3
votes
1answer
801 views
Does wp_insert_post validate the input?
If I use the wp_insert_post in a plugin, will I have to check the content for SQL injection problems and XSS or will the wp_insert_post function do this for me?
3
votes
2answers
257 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 ...
3
votes
1answer
1k 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 ...
3
votes
2answers
383 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), ...
3
votes
2answers
109 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()) ...
2
votes
1answer
417 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. ...
2
votes
2answers
342 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 = ...
2
votes
1answer
624 views
Using wp_insert_post() with Networking enabled
I'm working on a script that will drop articles directly into the wordpress database, using wp_insert_posts(). However, I have networking enabled and the wp_insert_post() reference page has no ...
2
votes
1answer
267 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:
/*
| ...
2
votes
1answer
172 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
2answers
124 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 ...
2
votes
1answer
238 views
Programmatically insert hierarchical terms & set terms for post causes glitch?
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. ...
2
votes
1answer
393 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 ...
2
votes
4answers
1k 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 ...
1
vote
2answers
216 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
2answers
904 views
What hook should be used to programmatically create a post only when master post is updated?
Pippin and Jean-Baptiste Jung have very good tutorials on how to programmatically create content when a new post is published using these four actions hooks...
publish{post_type}
...
1
vote
1answer
226 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 ...
1
vote
3answers
260 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 ...
1
vote
5answers
672 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
1answer
58 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 ...
1
vote
2answers
95 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
152 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
1answer
304 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 ...
1
vote
2answers
2k 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
1answer
715 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 ...
1
vote
2answers
2k 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 ...
1
vote
1answer
19 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 ...
1
vote
1answer
203 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 ...
1
vote
1answer
60 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
135 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 ...
1
vote
2answers
267 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
428 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 ...
1
vote
1answer
431 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( ...
1
vote
1answer
812 views
Insert post in another database
I have developed a custom script that uses wp_insert_post to create new posts, however i'd like to use similar code to create the same data in another wp database.
Could be this done on the fly before ...
1
vote
2answers
51 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
0answers
131 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 ...
1
vote
1answer
468 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
38 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
0answers
88 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' ...
1
vote
0answers
145 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 ...
1
vote
0answers
204 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";
...
1
vote
0answers
177 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 ...
1
vote
1answer
406 views
Programmatically Creating Page using $wpdb and getting 404 error
EDIT: Turns out I had a permalink issue that was causing the 404 error.
Original Posting below:
I am creating a page programmatically using $wpdb->insert() and the resulting page returns a 404 ...
1
vote
0answers
278 views
wp_insert_post not returning post ID? [closed]
I've had a read of the existing posts on here and still can't see why my instance is doing this, but I'm using wp_insert_post to add a post with some data it's given, and it's inserting the post just ...
0
votes
3answers
2k 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
3answers
2k views
Proper formatting of post_date for wp_insert_post?
What is the proper way to define the post date when submitting a post from the front end using wp_insert_post (Trac)?
My snippet now is publishing with the mysql time...
if (isset ($_POST['date'])) ...
