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
0answers
110 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
1answer
164 views

Define page template in wp_insert_post

How can I set which page template this page, created using wp_insert_post, uses? I want it to use template-blog.php This is my current function; add_action( 'admin_init', 'mytheme_admin_init' ); ...
0
votes
0answers
80 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
2answers
165 views

WP Insert post with post_thumbnail

Insert post thumbnail with 'wp_insert_post', i'm trying this code but does not work, the field 'get_field('imagem_do_produto') returns the url of the image, why not work? <?php $exists = ...
0
votes
0answers
92 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
2answers
99 views

Insert posting automatically based in acf field

good day I found a code that works, but it creates several posts of the same name, do not want that, he wanted to create only once post_type if the value is 'x', but he is creating a 'x' every time ...
2
votes
1answer
224 views

Endless loop with wp_insert_post and wp_update_post

I have an array $unqiues which contains URL's, I loop over the array with the code below to get the URL titles, insert a new post, update the post meta. Then I change the the posts title and name to ...
-1
votes
1answer
265 views

How to insert category and subcategory using 'wp_insert_post' function?

How would be the array, to insert a post category and subcategory? Thanks.
0
votes
1answer
168 views

after wp_insert_post need to get the post id

I have a function in function.php and it does wp_insert_post. how can I get the post id which just posted? when I do wp_insert_posts, it saves a PR value (unique and it saves in post-meta table). Do ...
0
votes
1answer
80 views

Custom terms inserting as single string with commas, not separated

I have a front end form, one of the inputs asks for a comma separated list of keywords which should each end up being a custom term, I just saw in the backend the terms are entered as single string ...
0
votes
1answer
101 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
150 views

wp_insert_post creating duplicate post with Safari

I have a front end form users use to create custom posts. It works fine with Chrome and FF, but when in Safari two posts are created. The code i'm using is below. I've tried a few conditionals shown ...
0
votes
1answer
227 views

Create WordPress posts from JSON array using plugin in admin

I'm writing a WordPress plugin that I'd like to do the following: Add a WordPress plugin admin page that contains a button When you click the button, it loads an array of JSON objects from a file, ...
0
votes
0answers
105 views

Add manually created post to private group? (User Access Manager)

I'm just wondering if there's one specific function in this plugin's APIs that takes a post (maybe its ID, maybe its title, anything) and adds it to a group that has certain privacy settings. I'm ...
0
votes
1answer
86 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
2answers
315 views

How to insert custom function into wp_insert_post

i'm trying to send push notification when the wordpress admin insert new post. I was looking for hours where to add my function and after a lot i found core function wp_insert_post inside ...
0
votes
1answer
657 views

post category in wp_insert_post

I'm building a wordpress theme where people can submit posts using wp_insert_post. The code below adds the post title but does not add the category specified by the user. Instead it puts it in ...
0
votes
1answer
219 views

front end posting

this source works with upload image, if without image upload, it works but 'redirect' doesn't work. what should I do?? Please let me know.. many thanks! if( 'POST' == $_SERVER['REQUEST_METHOD'] ...
0
votes
1answer
147 views

Front end posting, not working wp_redirect with 'cannot modify header information' error

Im trying to make front end posting page but, sometime 'wp_redirect' is not working with 'cannot modify header information' error. adding data is working well but I don't know why is working well ...
0
votes
1answer
147 views

Plugin to create Posts and Forums then choose category and parent forum

I need to create a plugin for a customer that will help him create posts and forums and place them in a category and choose if it's a parent or a child forum. Just created a GitHub Repo for my files ...
2
votes
2answers
231 views

How do I pass an array as an argument to a WP-CLI command?

I want to use WP-CLI to create some new posts with custom taxonomy terms assigned. The challenge is that wp_insert_post's tax_input argument only accepts arrays, which I would have to specify on the ...
0
votes
1answer
61 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 ...
1
vote
2answers
514 views

Faster way to wp_insert_post & add_post_meta in bulk

I have a csv file that I want to insert that consists of ~1,500 rows and 97 columns. It takes about 2-3 hours to do a full import and I'd like to improve this if there is a way. Currently for each ...
1
vote
1answer
68 views

Add CPT values to Database

I am not sure if this is something easy. I have a plugin with all the functionality needed for a custom post type: Filters, navegation... I need to create a lot of posts (with taxonomies) of this CPT ...
2
votes
3answers
1k views

How to set featured image to custom post from outside programmatically

I am trying to fetch and insert images outside the wordpress environment to a custom post via PHP. How to move/upload that image to wordpress upload directory year date folder format just like ...
1
vote
1answer
119 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
162 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
90 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
129 views

Script timeout when importing/inserting > 45-50 posts from an external table

Wondering if anyone can spot the obvious mistake or give me some guidance on where I'm going wrong. I should also state this is my first plugin with Wordpress, so I'm sure I have overlooked ...
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
851 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 ...
0
votes
1answer
94 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
57 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
144 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
262 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
243 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
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
711 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
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
443 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
182 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
493 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
375 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
425 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
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
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', ...