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
2answers
497 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
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, ...
0
votes
1answer
547 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
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)...
1
vote
4answers
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 ...
0
votes
2answers
789 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
530 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 ...
-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
609 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 ) &&...
1
vote
1answer
29 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
1answer
587 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 ...
0
votes
1answer
609 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 ...
0
votes
1answer
677 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(...
6
votes
3answers
2k views

wp_insert_post extremely slow on big table, direct query very fast

My posts table is about 600K, and I don't consider this big at all. Anyway wp_insert_post is becoming very slow. I am trying to import a huge list of hotel information into Posts. The list is about ...
0
votes
1answer
648 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
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
286 views

Auto-generated posts not showing in backend (but being counted!)

I have a custom post type with a custom backend page. I'm creating posts of that type using this code: $postarr = array( "post_type" => "product_settings", "post_status" => "...
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
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
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
3answers
944 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 ...
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
1answer
2k views

Cant get front end form to post to wordpress

Long time lurker, first time poster, and big time PHP noob. Apologies if my question is a little vague, but I have the code below and I know I'm doing some sort of schoolboy error but it just won't ...
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 '...
1
vote
2answers
7k 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' => $new_post_id),...
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->...
0
votes
1answer
433 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
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 ...
2
votes
1answer
445 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, ...
62
votes
5answers
106k views

How do I set a featured image (thumbnail) by image URL when using wp_insert_post()?

While looking through the function reference entry for wp_insert_post(), I noticed that there's no parameter in the array it requires which will allow me to set the 'Featured Image' for a post, ...
0
votes
2answers
504 views

How to combine multiple wp_insert_post into one in order to gain better performance

I need to insert about 300 posts into the DB programmatically. Usually i use wp_insert_post to do this job with one record each time, but this time I don't think it'll work well with hundreds of rows....
0
votes
2answers
461 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
450 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 ...
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
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: ...
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' =&...
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
2answers
1k 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 ...
4
votes
5answers
5k 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' => $...
-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
61 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
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
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
0answers
28 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 ( ! ...
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
136 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 \ --...