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

learn more… | top users | synonyms

0
votes
1answer
24 views

wp_insert_post featured image from library

I know there are a lot of posts about it, but I don't want to upload a URL image to the library, I already have the image in the library and its IP. How can I use it with wp_insert_post?
0
votes
1answer
105 views

Allow unfiltered HTML for not logged in users when saving a post

I'm using this code: $var1 = $_GET["t1s2ninput"]; $var2 = $_GET["t1s2pinput"]; $new_post = array ( 'post_title' => 'Title <dl class="variation"> <dt>Variation: </dt> ...
1
vote
0answers
295 views

How to set featured image in wp_insert_post

I have a register form with upload field and when the user registers i create a new post. I need to have the uploaded picture on the featured image of the post. I have see something like this but i ...
0
votes
1answer
159 views

Can wp_insert_post_data filter be used to save custom field data?

I have custom field data that I would like to modify on its way to the database. wp_insert_post_data filter seems to be the closest thing I can find to achieving this. I dumped the $data and $postarr ...
0
votes
1answer
63 views

How can I get some of a posts meta data whilst it is still inserting?

I'm trying to make a function where a child post of a certain post type inherits the same title and slug as its parent. I'm using WP Types to define my post types and their relationships. But I'm ...
-1
votes
1answer
64 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
1answer
284 views

WooCommerce wp_insert_post action firing on every save

function initial_product_data ( $post_id ) { // lets get out of here if this is not a new product if ( 'product' != $_POST['post_type'] ) return; // make sure the post isn't automagically ...
0
votes
1answer
60 views

wp_insert_post issue

I've got the following code in the 'functions.php' file of a wordpress theme $ppost_data = build_post( $pID, $pcontent, $pname, $ptitle, $pstatus, $ptype, $pset_comment_status ); ...
0
votes
1answer
587 views

Adding custom fields (post meta) before/during wp_insert_post()

Our code base has a ton of logic that executes as the post is inserted/created. However, some of that logic depends on custom post meta. The only way I know of to add post meta to a new post is like ...
1
vote
1answer
236 views

Creating a post from data returned from HTML form

I am trying to write a WordPress plugin and I have hit a bump. The Background: I have some data in a mySQL DB that I am using (each row has a unique ID and some other information I have added). I am ...
1
vote
1answer
845 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
410 views

post_date_gmt and post_date [duplicate]

I am inserting posts programmatically using wp_insert_post. A typical call would look like this: $news_item = array ( 'post_title' => $titleField, 'post_content' => ...
0
votes
0answers
31 views

Want a form to appear in a post via wp_insert_post, form tags appear, fields don't

I use wp_insert_post to import external data in WP3.8. Part of the post_content field is a small form, see below. $content="<table><tbody><tr>"; $content.="<td><form ...
0
votes
1answer
623 views

Insert Post using Ajax

I'm using the following code to submit a form from a Wordpress page. <script type="text/javascript"> $j=jQuery.noConflict(); $j(document).ready(function(){ ...
0
votes
2answers
445 views

post_status => publish not working

I have a front end form that let users submit a post. This is how i store the data when a post is submitted : if ( isset( $_POST['submitted'] )) { $post_information = array( ...
0
votes
0answers
55 views

How to get media-button on front-end

I am using wp_insert_post to allow non-logged-in users to add post, and would like to have 'add-media' button as well on front-end. I tried wp_editor, but I don't want the text editor, just the ...
2
votes
3answers
802 views

How to prevent duplicate slugs for wp_insert_post?

I have a function that creates a page when I create a post (so as to construct parent-child relationship trees). I'm using the $title of the post to create the page and this also creates a duplicate ...
2
votes
1answer
64 views

Wordpress tax_input only if logged in

I am working on a wordpress plugin where a save lead data by forms in my website. When a user submits the form the following code will run so a post in post type "lead" will be added. Almost ...
0
votes
0answers
64 views

WP Infinite loop

It is not working. add_action( 'save_post', 'jdev_save_custom_meta_box', 13, 2 ); function jdev_save_custom_meta_box(){ global $post; // Get our form field if( $_POST ) : if ( ...
0
votes
1answer
23 views

I need to dynamic insert post containing javascript from my other website?

I am trying to dynamicly add some content post (also containing some js), but the javascript part is filter out. I thought by using wp_set_current_user the js would be included. This is my main ...
0
votes
0answers
57 views

Insert custom post type with taxonomies

I am tryig to insert my custum post type with a specific taxonomies , but it doesn't work Here my Custum post type add_action( 'init', 'create_annonce' ); function create_annonce() { ...
0
votes
1answer
54 views

What is the right way to clean up $title before wp_insert_post?

I am using a function to insert some post data and i am having problems with the title/title - slug. The title is random selected from an array, some title have ?, ! or . (dots) I notice ...
0
votes
0answers
12 views

Post array not printing after post is published? [duplicate]

I'm using this function which displays the post array when I click Add new post. After the post has been published I do not see the array of the published post. What's wrong with the code? I've also ...
0
votes
1answer
220 views

Setting Post Date Returning “Notice: A non well formed numeric value encountered”

I am using wp_insert_post to create post. While executing that function, I also set post date to schedule the post publish date using some variables. Here is the part of my code: //Intervals ...
2
votes
3answers
2k views

How to set featured image to custom post from outside programmatically

I am trying to fetch and insert images outside the wordpress environment to a custom post via PHP. How to move/upload that image to wordpress upload directory year date folder format just like ...
0
votes
0answers
220 views

Prevent Duplicate Attachment When Using wp_insert_post

I am trying to use wp_insert_attachment while using wp_insert_post. It's successfully creating the post and attachment. It have no problem if I only use the wp_insert_post function, but when I ...
0
votes
3answers
183 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 ...
0
votes
0answers
42 views

Wordpress custom post type meta data erased upon creating a new custom post type in gravity forms gform_after_submission hook

I'm running into an issue with gravity forms and custom post types. I have a PostType called Project that I display with gravity forms. Upon submitting the form I hook into gform_after_submission and ...
6
votes
3answers
8k views

Attaching taxonomy data to post with wp_insert_post

I am implementing (trying) a front end posting system which shows taxonomy data in several dropdown select fields, each of the dropdowns is named by using the "name" $arg in wp_dropdown_categories. ...
0
votes
1answer
109 views

Add action to create new post after wp_insert_post fires? Think it's creating an infitnite loop

I need to take the post meta from a post, and create a custom post type post. I'm using the code below but think it's creating an infinite loop. When wp_insert_post fires I have create_cptpost ...
1
vote
2answers
82 views

using wp_insert_post inside of custom meta box

This is kind of a unique situation. I have an invoicing custom post type that when it is marked as "paid" I want to then generate another custom post type. I have a custom meta file that handles the ...
2
votes
1answer
63 views

Can we have a post without a slug?

When I insert a post I've found that there is a slow call to wp_unique_post_slug from within insert_post (In the database I'm using to test there is 155,000 posts - live would have considerably more). ...
0
votes
1answer
354 views

function wp_insert_post and wp update_post_meta [duplicate]

how combine wp_insert_post and wp update_post_meta? i need first insert post, then update post, let me know about example? i want sample for my future project Thanks
0
votes
1answer
211 views

Insert two row in wordpress database

Hello I am working on a template where I have to grab some value and insert them in my own created table in wordpress database. Now as I dont know how to insert record in wordpress database , so i am ...
0
votes
1answer
127 views

create parent post using wp_insert_post

how can i create php function where i can create a post in one custom post type also create a child post type, i have already create a parent post type, i.e post type "a = car" post type "b = user" ...
1
vote
1answer
759 views

Programmatically Creating Page using $wpdb and getting 404 error

EDIT: Turns out I had a permalink issue that was causing the 404 error. Original Posting below: I am creating a page programmatically using $wpdb->insert() and the resulting page returns a 404 ...
1
vote
1answer
309 views

WP_INSERT_POST issue on Wordpress Multisite

Im having a hard time on fixing this issue of mine. I have a plugin where it creates 6 pages at default for new wordpress multisite sites. Im using the following code. function ...
0
votes
0answers
151 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 ...
1
vote
1answer
294 views

Define page template in wp_insert_post

How can I set which page template this page, created using wp_insert_post, uses? I want it to use template-blog.php This is my current function; add_action( 'admin_init', 'mytheme_admin_init' ); ...
0
votes
0answers
87 views

Update fields with post object and custom tax with wp_insert_post

Updated Post 'update_field' Function is Acf Plugin $supplier_one = 'my supplier'; $supplier_two = 'my supplier TWO'; $post_id_one = 555; $post_id_two = 556; update_field('suppliers', $supplier_one, ...
0
votes
2answers
200 views

WP Insert post with post_thumbnail

Insert post thumbnail with 'wp_insert_post', i'm trying this code but does not work, the field 'get_field('imagem_do_produto') returns the url of the image, why not work? <?php $exists = ...
0
votes
0answers
118 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 ...
0
votes
2answers
114 views

Insert posting automatically based in acf field

good day I found a code that works, but it creates several posts of the same name, do not want that, he wanted to create only once post_type if the value is 'x', but he is creating a 'x' every time ...
2
votes
1answer
259 views

Endless loop with wp_insert_post and wp_update_post

I have an array $unqiues which contains URL's, I loop over the array with the code below to get the URL titles, insert a new post, update the post meta. Then I change the the posts title and name to ...
-1
votes
1answer
400 views

How to insert category and subcategory using 'wp_insert_post' function?

How would be the array, to insert a post category and subcategory? Thanks.
1
vote
4answers
4k 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
1answer
305 views

after wp_insert_post need to get the post id

I have a function in function.php and it does wp_insert_post. how can I get the post id which just posted? when I do wp_insert_posts, it saves a PR value (unique and it saves in post-meta table). Do ...
3
votes
2answers
307 views

How do I pass an array as an argument to a WP-CLI command?

I want to use WP-CLI to create some new posts with custom taxonomy terms assigned. The challenge is that wp_insert_post's tax_input argument only accepts arrays, which I would have to specify on the ...
0
votes
1answer
102 views

Custom terms inserting as single string with commas, not separated

I have a front end form, one of the inputs asks for a comma separated list of keywords which should each end up being a custom term, I just saw in the backend the terms are entered as single string ...
0
votes
1answer
120 views

Insert a Woocomerce product in specific product category

I'm a bit new to Woocomerce plugin and have a problem. I need to create products from code not from admin page. Probably I will insert them with wp_insert_post( $product ). The problem is I don't ...