Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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

0
votes
0answers
34 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
0answers
18 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
30 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
23 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
19 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
31 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
39 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 ...
0
votes
0answers
23 views

Use a cron job to automatically create posts based on dates

I have a custom post type called cpt1. I need to run a function that on a daily base Loops through cpt1 and then check the dates. This is done by using cron job to trigger. Within this loop ...
1
vote
1answer
25 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), ...
0
votes
1answer
30 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
181 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
36 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
19 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
129 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
43 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
25 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
70 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
30 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
220 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
2answers
397 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
61 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
21 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
170 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 ...
4
votes
1answer
110 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
0answers
40 views

Deleting custom post type from external API via wp_delete_post

I've been working with an external API to pull in data and create what's essentially a job board via custom post types with wp_insert_post. My concern is that once these jobs/custom posts are removed ...
0
votes
1answer
232 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
21 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
63 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
36 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
0answers
21 views

How to set canonical url for wp_insert_post created post?

I creating posts with wp_insert_post, and I want set for these posts canonical urls... How can I do this? Any idea is it would be fine. In a perfect world I could use an option for this in my array......
0
votes
2answers
132 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
59 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
82 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
43 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
73 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
89 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
200 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
163 views

Cannot add posts via wp_insert_post(). Gets database error

I am trying to add a post via an external file, but I keep getting an error: WP_Error Object ( [errors] => Array ( [db_insert_error] => Array ( [0] => Could not insert post into the database ...
0
votes
0answers
22 views

how to use wp_category_checklist() to insert via wp_insert_post()

I'm wondering in which way i can process the ticked categories and submit them into the array: $my_post = array( 'post_title' => $title, 'post_content' => '[play_video url="'.$link.'"]', '...
0
votes
2answers
373 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, ...
1
vote
1answer
70 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
20 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
112 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 ...
0
votes
0answers
157 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
2answers
343 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 ...
1
vote
0answers
30 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 ...
1
vote
1answer
327 views

wp_insert_post is not creating revision in database

I am creating custom frontend post submission form. I am using wp_insert_post for creating new post. The function is working fine but it is not creating the revision record in database. Following is ...
1
vote
0answers
45 views

Is there a better way to programmatically insert content into a page?

During activation of the plugin I'm writing, I insert a custom page. I can add post_content using the wp_insert_post command, which seems like a reasonable way to add a limited amount of content. For ...
0
votes
1answer
44 views

how to call other plugins once custom post has been inserted

i built custom script to import woocommerce product using (wp_insert_post) and i want to call other plugins to insert their data to each new products to db for example: after inserting product if i ...
0
votes
1answer
113 views

Why insert post function do not set the modified author without administrator panel?

I am have a front-end new post and edit post forms. I'll using the <?php wp_insert_post( $post ); ?> Everything is all right here. If any editor or admin modified any author posts on front-...