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
1k 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
0answers
377 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 ...
4
votes
3answers
11k views

advanced custom fields update_field for field type: Taxonomy

I need to insert a post via wp_insert_post and then add relevant post_meta - however, the WP admin has been customized with the excellent ACF. I know I can add_post_meta in this way: add_post_meta( $...
0
votes
1answer
1k views

Getting error when using wp_insert_post()

When I use wp_insert_post() I get a white page that says "Are you sure you want to do this?". I get no PHP errors. I am using this outside of wordpress and have wp-load.php as well as /wp-admin/...
0
votes
1answer
630 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
745 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(...
0
votes
1answer
31 views

WordPress PHP custom function is causing 500 Internal Server Error Connection Timeout

I wrote a custom script to insert a post into WordPress and upload 3 images to the WP uploads directory. To write the post I use the WP function wp_insert_post( $wp_post_array, true );. Inside the ...
0
votes
1answer
721 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
1answer
25 views

How to save post with different languages and linked them with WPML?

I received a php object ($binding_main_cpt) built from an external API like this : array ( 'post' => array ( 'en' => array ( 'post_title' => 'Villa with magnificent sea ...
0
votes
1answer
30 views

wp_insert_post() with HTML tags using PHP

This question seem to be unanswered. I find myself stuck on it. Here it goes I've a problem with WP API to insert a post with HTML Tags. I'm using the method: wp_insert_post() and the content is ...
0
votes
0answers
8 views

No ACF post meta when using get_post_custom during save_post

When I save/publish a page, I want it to save to all blogs in multisite including its custom fields (using Advance custom fields). The problem is that, when I tried to look at the value of post_meta ...
1
vote
2answers
1k views

Use of wp_insert_post and parameters

I've JUST started using WordPress..i'm trying to add posts to Wordpress using php and i came across this piece of code: // Create post object $my_post = array( 'post_title' => 'My post', '...
0
votes
0answers
14 views

Cannot insert HTML content even removing kses filters

I am creating post using the following code, but I cannot make the HTML content go through, they are being stripped automatically.. $post_data = [ "post_title" => $question, "post_content" =&...
1
vote
1answer
27 views

How to use wordpress $polylang->model->set_post_language in custom php code?

I am creating a custom content engine that posts artwork content (uploading images from dropbox, building the content from data in an Excel spreadsheet, using a custom table for content management etc....
1
vote
1answer
10 views

Cron job for creating posts not excecuting properly

I've written a PHP script to create custom posts programmatically from Google Calendar events, and an action hook that purges all existing events and repopulates it with current ones. This works fine ...
0
votes
1answer
19 views

How do I find out which (page) template file my custom child post is looking for?

I am trying to make something like a web-app with WP. One of the issues I'm facing now is that I cannot find out which page template file my post is looking for. I have looked at template file ...
0
votes
0answers
14 views

Wordpress New Post via ajax call

I have added this field to the Add New Post page And i get data via ajax into console, I want to update post title and content when i click button "Import Data". jQuery(document).ready(...
0
votes
1answer
16 views

Sanitize WordPress Array Input?

I have a form that submits the data in array format. I have sanitized all the data and also tried to escape it using esc_attr, but it is a function of escaping and not sanitizing. Is there a better ...
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
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 ...
19
votes
4answers
12k 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 ...
5
votes
6answers
7k 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
3answers
2k 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
0answers
133 views

Add PHP block template to content using wp_insert_post

I have created a block template so that every new post starts with a certain collection of blocks. In the below reduced example, let's say that the block template contains just a heading block and a ...
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
508 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 ...
0
votes
1answer
447 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 ...
3
votes
1answer
493 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
2answers
717 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
1answer
471 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 ...
1
vote
2answers
486 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
2answers
568 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
2answers
313 views

Custom Post Type & Author not associating, user post count is 0, api doesn't return author in post objects

When Users create custom post types, the author field does not seem to be passed back to WP posts functions. As the title says, I'm creating a user account programatically, and having that user log-...
0
votes
1answer
636 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
602 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
vote
1answer
2k views

Can't get wp_insert_post to work

I'm trying to code a loop that will post articles from a SQL database. However, whenever I try to load the page I get a 500 error and nothing is showing up in the error logs. Code: <?php define('...
10
votes
5answers
42k views

Proper formatting of post_date for wp_insert_post?

What is the proper way to define the post date when submitting a post from the front end using wp_insert_post (Trac)? My snippet now is publishing with the mysql time... if (isset ($_POST['date'])) {...
0
votes
0answers
27 views

wp_insert_post() Add and specific ID to the body of that

Is there a way to add an specific ID to the body of that post that it's created by that method? The thing is, I'm creating a new post using this $new_page = array( 'post_type' => ...
0
votes
2answers
676 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
332 views

Is this the correct way to add post-slug input field?

I added slug input field in my custom post type and allow users to edit it at front end. Then, when insert post, I use this: $wp_insert_post_args = array( 'post_status' => 'publish', ...
1
vote
1answer
28 views

wp_insert_post generates endless posts

I'm using wp_insert_posts to programmatically create a post but it keeps generating the same post endlessly. I'm using a custom post type called irl-today. It does generate one post if I'm using the ...
0
votes
2answers
424 views

wp_insert_post not working fine

I asked my question on stackoverflow but I did not get any answer, may be because it's the question related to Wordpress.So I am asking it here. I am using wp_insert_post function to insert my posts, ...
0
votes
1answer
61 views

wp_insert_post deleting previous post custom meta

I have created a custom post type called "pay stub" and two custom meta fields "net pay" and "link" (the link to the pay stub file) and two custom taxonomies, "status" and "employee". I set the ...
1
vote
1answer
42 views

Frontend submission upload image via external url

I have AJAX form to get movie data by movie id and post this data into new post. This is my function, It's works very well, But i can't upload image via external URL. // Image URL $poster = '//...
0
votes
0answers
108 views

Random post_id at wp_insert_post

How I can use an absolute random post_id in wp-admin at wp_insert_post? I need stored in wp-admin a unique random post_id, but not I have only: 2210, 2212, 2214. As I understand it, this will not work ...
2
votes
1answer
61 views

How to allow data:image attribute in src tag during post insert?

I'm inserting a post using wp_post_insert(). And my post's content looks like this: <img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAN4AAAB6CA { ... } but on the insert process, ...
0
votes
1answer
85 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
vote
0answers
92 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 ...
-1
votes
1answer
97 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
2 3 4 5
8