Questions tagged [wp-insert-post]

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).

Filter by
Sorted by
Tagged with
2
votes
1answer
86 views

Created pages not showing up in 'All Pages' list

Due to some custom software integration, I have my theme generate some pages automatically with set templates in order to achieve the required functionalities. I do so with the following script: (...
0
votes
1answer
143 views

wp_insert_post with ACF Fields and WP Meta Query returns no rows until update

I’ve been reading a lot how you can’t use wp_insert_post and update_field because the field isn’t created yet or sum such, so I’ve experimented with MANY permutations of wp_insert_post. My field is a ...
0
votes
1answer
145 views

Meta inserted through wp_insert_post gets messed up

I'm extending the Woocommerce Product CSV Import functionality to import more data. I'm inserting a CPT with 2 metadata, a string (URL) and a bool, and the post_meta inserted gets messed up. It ...
0
votes
1answer
85 views

WP-CLI --meta-input error: Warning: Invalid argument supplied for foreach()

I'm using this code to import posts from a csv file, which works great except for the meta_input (custom fields) while IFS=$'\t', read -r col1 col2 col3 col4 col5 col6; \ do \ wp post create \ --...
8
votes
6answers
23k 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
172 views

tax_input in wp_insert_post partly not working

I'm inserting a post via wp_insert_post() and in the $args the tax_input looks like this: 'tax_input' => array( "programmas" => 'Modern Family', "zenders" => 'ABC', ), But what is ...
14
votes
4answers
11k 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
votes
2answers
45 views

Create a new page on front page for logged in user

I am going to find a way for logged in users to create pages from front page. For example there are three buttons so called button1,2,3. When logged in users clicks on button1, a page with title ...
1
vote
1answer
47 views

Check if post is added manually or through wp_insert_post()

I might not be thinking this right but here is my situation: I have a custom post type called events. Some of my events are imported from an API and inserted through wp_insert_post() (in a plugin), ...
3
votes
7answers
7k 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 ...
0
votes
3answers
1k views

How do I insert a post with custom post type and relate it to a custom taxonomy?

I'm trying to figure out how to insert a new post. I have a custom post-type (course) that is related to a custom taxonomy (categorycourses). I've managed to insert a post with custom post type ...
3
votes
1answer
327 views

Speeding Up Bulk Post Creation - wp_insert_post & update_post_meta

I am creating posts (variable products) using (wp_insert_post) function. An Example, I have 9 colors, 9 sizes. Which makes 9×9 = 81 total variations for 1 product, which is 81 times below function to ...
10
votes
2answers
7k views

What is “meta_input” parameter in wp_insert_post() used for?

I am inserting some post into wordpress using the function wp_insert_post(). I want to insert some custom fields on each post and reading the documentation I though the meta_info parameter was used ...
0
votes
1answer
119 views

Set page template programaticlly in plugin

Task: I have created a page using my plugin and that page has to be set a certain page template within page creation. Everything works apart of setting page template. I have manually moved page ...
0
votes
2answers
189 views

add_user_meta allows multiple clicks and inserts more than 1 value

I've just checked a double click on my form that inserts new user meta, which actually inserted it twice! The problem is, I actually need the values to be non-unique so I can insert multiple times. ...
0
votes
0answers
21 views

Generate post content from meta fields

I have a custom post type (match). Each posts on this CPT has one ore more custom fields. Is it possible to automatic generate the 'post content' with the value of my custom fields on these posts? ...
1
vote
2answers
476 views

How to upload multiple image using wp_insert_post

Im using wp_insert_post to add products on the front end of a woocommerces site My current code will upload all the images but only the last image will be in the product gallery images heres my code;...
3
votes
4answers
4k views

How do I programmatically add items of content to a custom post type?

I have a custom post type to which I'd like to programmatically import data. I have followed these instructions and these, and I can easily do it for WP typical pages and posts. However, my custom ...
0
votes
1answer
92 views

How to handle new post from API request?

I feel silly for even asking this, as it seems like it should be very straightforward but I'm having a hard time finding this information. Goal: Make a POST request to the WordPress API with new post ...
0
votes
1answer
112 views

On save_post need to wp_insert_post and save partent post id to child post and child post id to parent post

I'working on plugin for custom post types and it's metadata etc. Everything is fine so far but now I need to extend this plugin - I need to create one extra the same custom post on save/edit post when ...
0
votes
1answer
86 views

wp_insert_post inside save_post adds wrong metadata to inserted post

I have code for saving metadata for Student post_type. While saving metadata I also want to add separate posts for each payment in payments array: add_action( 'save_post', 'save_student_meta' ); ...
0
votes
2answers
752 views

wp_insert_post() get Fatal Error from Plugin

I'm realizing a sort of "page" inside admin area to insert post manually without the default method. This is only the begin... Anyway, after firing Insert button of the form, the article is inserted, ...
0
votes
1answer
464 views

Post meta data not showing in frontend, until hitting 'update' button

I try to insert around 2000 video-posts into WP. There is a custom field in the theme for the video-url, so I add the video-url to the post meta data with the corresponding field name. ACF seems not ...
0
votes
1answer
85 views

wp_set_post_terms() seems very slow

Is it normal for wp_set_post_terms() to be very slow? When wp_insert_post() it takes about 1 second. Adding 4 wp_set_post_terms() 7 - 10 seconds to the operation. Pseudo code example: $values = ['...
0
votes
1answer
339 views

wp_insert_post not inserting post

I'm trying to insert a post when a user (aka me) clicks on the button (this button is inside a meta box on the admin dashboard). This doesn't happen and I don't know why. When I put the content of my ...
3
votes
1answer
192 views

Not Able to Insert Taxonomy Term Using wp_insert_post()

I have a Custom Post Type called eyeglasses and Custom Taxonomy called models. I also created two terms for taxonomy called M156 and M120. Now I am trying to upload two post for test through ...
0
votes
1answer
844 views

Inline style HTML attribute is being stripped from all elements of a post

I am attempting to publish HTML generated from an external party within Wordpress, but I am getting very inconsistent results with style attribute on all HTML elements, in that if I programmatically ...
0
votes
2answers
459 views

Add new post in existing categories using wp_insert_post

I am trying to add a new post using the function wp_inser_post in one of my existing categories, I've created a new taxonomy named categorie and in that taxonomy i have a few categories, and I am not ...
0
votes
0answers
23 views

Published page but it is page not found

I have published page with post type abc, but the page is not found. If I keep post type, then it works fine. I insert post data and publish through query: add_action( 'init', 'my_cpt_init' ); ...
1
vote
1answer
51 views

Don't insert if permalink is the same?

I have a foreach loop inserting posts. And I already have statements to check if post already exists by unique meta values. But somehow, often when site is loading slowly, something strange happens ...
0
votes
1answer
416 views

$wpdb->insert() does not insert fields

I need to insert banner data into a table wp_rdp_banners. To work with the banner data I insert the full affiliate link and also split it to save the banner url and banner image location into ...
2
votes
1answer
146 views

Can I edit the wp_post > post_content right before its inserted/updated?

I would need to apply some sort of encryption on whatever gets inserted in the wp_post > post_content, so I was wondering if there is a way, either modifying the core (rather not), or using some ...
0
votes
0answers
123 views

Programmatically create new post from a metabox button

Given a classic course-lesson structure, created by custom post types, I want to add a new empty lesson for a course, by using a simple html form on a metabox, in the course edit screen. I think I ...
0
votes
4answers
3k views

wp_insert_post custom taxonomy

I have a custom post type books and a custom taxonomy books-categories. wp_insert_post() and it works. How can i add a second taxonomy called location? This code doeasn't save my custom taxonomy ...
2
votes
1answer
103 views

Using table lock with wp_insert_post?

I'm running a cron every 5:th minute that inserts a lot of posts. Sometimes it happens that those crons are running both at the same time. To be sure that not causing duplicate posts. I would like to ...
1
vote
1answer
131 views

Could not get post ID from wp_insert_post()

function cgp_create_post($title, $name){ $new_post = array( 'post_title' => $title, 'post_type' => 'custom-post-type', 'post_status' => 'publish' ); ...
0
votes
1answer
124 views

Issue with wp_insert_post() when post_content contains links?

When I create a post using wp_insert_post() if the post_content contains an HTML link I'm getting a copy of the post_content in the <head> and the <body> of my post HTML page. The strange ...
0
votes
1answer
846 views

Inserting current user ID into Post for Author

I am trying to insert the user id of the current user when creating a custom post type. This is my code: $my_post = array( 'post_title' => $orderRequestCode.' - ' . $customerName, ...
1
vote
1answer
201 views

Creating New Page with WP_INSERT_POST Issue

I am trying to create a new page using the wp_insert_post() function as follows: $page = array('post_type' => 'page' ,'post_title' => 'The Resolution AR' ,'...
0
votes
1answer
929 views

Check for duplicate custom field value before running wp_insert_post

That is, I want to prevent 'guid_review' ACF value being duplicate by checking it before creating the post. foreach ($items as $itemKey => $item) { $myPost = array( '...
0
votes
1answer
2k views

Set default Custom Post Meta Value

I've tried almost anything and just can't get this to work. I have a custom post type with a custom meta field and I want a default value to be added on when the Publish/Update/Save button is pressed....
1
vote
1answer
98 views

Use wp_set_post_terms() instead of wp_insert_post()

Since I use cron jobs for automation I ran into some problems with the taxonomy. Before I used the cron job, the following code used to work: $custom_tax = array( "project-type" => array( ...
0
votes
0answers
295 views

Is it possible to use 'wp_insert_post' function within a for loop?

I want to insert as a custom post type some data fethced from an API, I store that data and then pass it trough a for loop, then I use the loop data to create an array to pass it to wp_insert_post ...
1
vote
3answers
7k 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 https://stackoverflow.com/questions/5759359/wordpress-manually-set-...
0
votes
0answers
21 views

Checkboxes to automatically create pages when I activate a theme

So, I want to create pages automatically on theme activation. This seems kinda easy with wp_insert_post(). The problem is: I need to select only certain pages to be created. Is there a way to do this?...
0
votes
0answers
156 views

Meta keys won't add using wp_insert_post

I have the following code, I am attempting to insert a new post with the 2 meta fields attached, the post is being inserted but the meta isn't there. Can't seem to spot anything wrong here, so what's ...
1
vote
2answers
481 views

How to auto increment post title & post slug field?

I've a custom Post Type i.e. prj and need to auto increment it's post_title (title) and post_name (slug) on post save, update regardless of the post status .. the post can never be deleted that's why ...
0
votes
1answer
1k views

Bug in wp_insert_post script and form, probably something simple I am not seeing

OK, I have been working on debugging this script for 2 and a half days now and am coming up empty. Basically, this is a front end form that will insert posts based on the script that I wrote for it at ...
1
vote
1answer
1k views

Get data from wp_editor()

I can use wp_editor() function for add custom post use wp_insert_post() function (with post_content parameter) in my plugin. I need to can be saved data from wp_editor() function. How can i get ...
1
vote
0answers
36 views

When User Meta amended update Title and Slug of Post programatically

I have this code below which works perfectly, i.e. when adding a new User a post is programatically created in my CPT. add_action( 'user_register', 'add_member_employees' ); function ...