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

How to know find the input id for use it on wp_insert_post

I made wp plugin for automatic posting require 'crawel.php'; if (isset($_POST['activated']) && is_admin()){ $new_page_title = $manga_name; $...
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 '...
0
votes
1answer
4k views

Action hook “wp_insert_post” works but not for last imported post

I want to run a custom function whenever posts are imported to my custom post type. I am currently running this code - function on_post_import($post){ global $wpdb; $results = $wpdb->...
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' =&...
0
votes
2answers
392 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 ...
1
vote
3answers
6k views

How I upload, save and set a featured image from my frontend?

I have a form on my site. This the user register one missing person. I created a custom post type missing person, custom taxonomies, and custom fields. All this input's save as well in wp. But I ...
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
378 views

How to Create Content Remotely

I'm trying to help populate a newly setup wordpress website and am trying to write scripts to do automated posting of a pre-processed archive of e-mails as a series of posts and comments. I'm ...
0
votes
1answer
22 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 ...
2
votes
1answer
403 views

How can I stop wp_update_post messing up HTML example code?

I'm showing little pieces of example HTML/PHP code on the frontend (with syntax highlighting). The entries are displayed as FAQ custom posts, and have a plugin (CMS Tree page) to alter the menu order, ...
0
votes
1answer
398 views

Pay before posting (frontend insert post)

I have a form on the frontend which I want users to fill out, when they have I want to save the data and redirect them to pay before submitting the post. How do I save the data before they pay? I ...
3
votes
4answers
4k views

tax_input not working wp_insert_post

I am using wp_insert_post and all the fields are working except tax_input is working. Is there something wrong with my code? $customtax = array( 'product_link' => $link, 'product_price' => $...
0
votes
2answers
424 views

wp_insert_post via shell category not being inserted

I'm using this code: $post = array( 'post_content' => $desc, 'post_title' => $name_new, 'post_status' => 'publish', 'post_type' => 'portfolio_page', ...
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
2answers
433 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, ...
0
votes
1answer
452 views

Get original post ID after wp_insert_post

I have a plugin with several CPTs (we'll call them CPT-A, CPT-B, CPT-C, and CPT-D). All CPTs have custom fields. In CPT-D, the user is able to make a selection and assign a post in CPT-A, CPT-B, and ...
0
votes
1answer
465 views

wp_insert_post does not insert string with apostrophes correctly

I'm using wp_insert_post (for several reasons) in a script I'm writing and it's causing any string that has an apostrophe in it to be truncated up to that character (including the character). Here's ...
2
votes
1answer
889 views

How to add multiple product gallery images from front-end

-I am running a woo commencers shop -Users have the ability to add products using wp insert post -The product gallery multiple image upload will only add the last image to the post but in media they ...
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 \ --...
8
votes
6answers
20k 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
69 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 ...
1
vote
1answer
531 views

Cropping an image before inserting into a post

I've got a frontend post form, and I've been using this PHP code to allow uploading an image and to insert it into a post. // image upload and attatching to post if ( ! empty( $_FILES ) &&...
0
votes
1answer
563 views

wp_insert_post custom type and custom taxonomies

I have a custom post type books and 3 custom taxonomies attached to books. The custom taxonomies are: books-categories , location , services_c. How should i edit my form to get my taxonomies work; I'm ...
13
votes
4answers
9k 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 ...
0
votes
1answer
535 views

Problem on wpdb queries, wp_insert_post, wp_insert_user etc. The query runs twice

Anyone encountered this issue? I have created a custom php script which adds a new post by using wp_insert_post() but everytime I run the code it creates a 2 new post where in it should be only be ...
-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
1answer
582 views

Help to upload post attachments from Ajax

My problem is that I cannot upload post attachments from a frontend form. I send data through AJAX to my php files containing functions. Let me be clear: everything is working great, the post is ...
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
629 views

How to insert post from external php file?

I have this php file on the root directory, and i seen this example for inserting post from external php file but for some reason it doesn't work for me, wp_insert_post() always returns 0 So whats ...
0
votes
1answer
642 views

php wp_insert data on front using a form

I'm using a form on my website to allow user to create posts on my wordpress admin. It works fine, but I have an issue, I don't get the tags meta inside my admin. here is my php code : <?php if(...
2
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
180 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
6k 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
1k 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
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 ...
2
votes
1answer
1k views

Organizing uploaded media with wp_insert_post() and wp_handle_upload according to time parameter

I'm retroactively creating a post with wp_insert_post() and attaching a featuring image to it. I need the image to go into the folder that corresponds to the post's publishing date. I'm using time ...
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. ...
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
127 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
3k 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
42 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
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
2answers
372 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
216 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
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
20 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="...