We’re rewarding the question askers & reputations are being recalculated! Read more.

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
0
votes
0answers
12 views

Auto-Select Parent Category as Primary

I am using Yoast SEO Premium to handle the selection of Primary Categories. I am currently working with a Listing (listing) custom post type with a hierarchal taxonomy of Listing Category (listing_cat)...
0
votes
1answer
22 views

wp_insert_post($post), add an array of values with update_post_meta

i try to store an array in multiple custom fields via post creation (wp_insert_post). The array is $event_test and the key is event_test on the meta_input. On form submit, the custom field is shown, ...
-1
votes
1answer
13 views

add multiple values (array) to post meta_input

i have a custom post type where a post is generated by a form submit. One key is an array which should be stored in a custom field... i shortended the code below to the important part -> they key is "...
1
vote
1answer
28 views

wp_insert_post not working

I'm trying to get the movie info from the omdb web service and it worked fine but it doesn't work when I want to use wp_insert_post to create new posts. This script acts as the user enters the movie ...
0
votes
2answers
14 views

How to prevent wp_insert_post from creating a new post every second?

I am trying to create a simple plugin that creates only one new post. The code I have written creates a the same new post every second. Below is the code I have. What would need to be added so it ...
0
votes
0answers
15 views

Programmatically Upload Image to Media & CDN

I'm trying to create a feature that allows my website to: Crawl through a CSV file and programmatically create a post Upload a featured image based off a URL from the CSV file to the Media Library (...
0
votes
2answers
30 views

When creating a post how do you select the format?

When creating a post programmatically (with wp_insert_post();), how do you select the format?
0
votes
0answers
21 views

WC attributes and terms cannot be added with the first pass of the script

In general, I am trying to insert/update post of type 'product' with attributes and terms into tax_input. It does not happen as expected. Firstly I tried to use wp_insert_post with 'tax_input' key ...
0
votes
0answers
22 views

Updating failed message when a wp_insert_post function is hooked to save_post hook

I was creating a function which creates a new custom post type with the category or taxonomy name if it was created from the post editor. I am simply using the wp_insert_post function with the ...
0
votes
1answer
26 views

how to create a category with wp_insert_post and post_category

I am trying to create a post with php and its wordpress functions. I am using wp_insert_post () but I can not assign a custom category type text to the post nor create it I have this code: ...
0
votes
1answer
14 views

Creating categories while importing via CSV

I have a CSV that I am importing via a custom plugin I made. This will create a CPT that has a few ACF fields. This CPT is called Formula, and it has a taxonomy associated with it called formula_type. ...
-2
votes
1answer
52 views

Is there any point to using wp_unique_post_slug?

From what I can tell, wp_insert_post will automatically append a -# to your post slug. So why does wp_unique_post_slug exist? Is it just there for legacy purposes or is there still a good reason to ...
0
votes
1answer
60 views

WordPress hook which triggers on post import

I am adding few meta fields for product post type using wp_insert_postaction and it is working perfectly. But I have to trigger my function upon product imports as well as this action is not firing ...
0
votes
1answer
32 views

wp_insert_post with data from graph api inside a plugin

I'm creating a plugin that creates a post in a CPT for every Facebook page post (using fb graph api). When should I fire the function that gets the data? using an action? Also if I understood the docs ...
0
votes
1answer
79 views

permalink not showing correctly using wp_insert_post and post_name

So I am using wp_insert_post() to create new posts dynamically. But I am trying to achieve the permalink structure to Parent/Child page as: Parent/Child/GChild or mydomain/MYTitle/1/1/ (yes I want ...
0
votes
0answers
27 views

wp_inset_post not adding taxonomy (using wp_set_object_terms)

The following runs through a cron job and successfully creates and publishes the post to a custom category. However, it does not attach a custom taxonomy (ap_job_status) term (ID 3) to the post. $...
0
votes
0answers
66 views

get_page_by_title() not working as expected

I'm looping through an API with jobs and creating new posts from it like this: //fetch jobs and loop through them... // check if post title exists, if not add it. if ( ! ...
1
vote
1answer
168 views

How to checked selected category checkbox when my custom post inserted from frontend

if ( isset( $_POST['save'] ) ) { if(wp_verify_nonce($_REQUEST['_nonce'], 'submit-post')){ // $userid = get_current_user_id(); $atts = array( 'post_content' =&...
2
votes
1answer
68 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
137 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
135 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
78 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 \ --...
-1
votes
2answers
44 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
41 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), ...
1
vote
2answers
48 views

Can't publish post using ajax

I have an issue, i create three input in frontend(title, body, and name) I process the value using wp-ajax, and in my ajax function I use wp_insert_post to create a new post. if I put '...
3
votes
1answer
289 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 ...
0
votes
1answer
102 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
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
427 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;...
0
votes
1answer
87 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
101 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
156 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 ...
0
votes
1answer
77 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
1answer
437 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
3answers
943 views

Set Primary category using the Yoast SEO plugin

function set_primary_on_publish ($post_id) { global $post; $categories = get_the_terms( $post->ID, 'category' ); // wrapper to hide any errors from top level categories or products ...
0
votes
1answer
82 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
0answers
29 views

Create posts by any logged in users

I want to allow logged-in any users to create posts. For this purpose I created a form <form> <div class="form-group"> <input type="text" class="form-control" id="...
0
votes
1answer
311 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
180 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
780 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
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' ); ...
2
votes
1answer
137 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
99 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
2answers
185 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. ...
2
votes
1answer
97 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
125 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' ); ...
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
113 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 ...
1
vote
1answer
188 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
2answers
415 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 ...