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
286 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
591 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
848 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
414 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
624 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
448 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
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
225 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 ...
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
185 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
44 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 ...
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
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
355 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
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
237 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
311 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
295 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.
0
votes
1answer
306 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 ...
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 ...
0
votes
1answer
178 views

wp_insert_post creating duplicate post with Safari

I have a front end form users use to create custom posts. It works fine with Chrome and FF, but when in Safari two posts are created. The code i'm using is below. I've tried a few conditionals shown ...
0
votes
1answer
273 views

Create WordPress posts from JSON array using plugin in admin

I'm writing a WordPress plugin that I'd like to do the following: Add a WordPress plugin admin page that contains a button When you click the button, it loads an array of JSON objects from a file, ...
0
votes
1answer
94 views

Set post_parent from URL params in post-new.php

I'm trying to create a set of buttons on wordpress Page post types that allow the end user to create a new page that is a sibling (same parent page) or a child page of the current page. In order to ...
0
votes
2answers
464 views

How to insert custom function into wp_insert_post

i'm trying to send push notification when the wordpress admin insert new post. I was looking for hours where to add my function and after a lot i found core function wp_insert_post inside ...
0
votes
1answer
845 views

post category in wp_insert_post

I'm building a wordpress theme where people can submit posts using wp_insert_post. The code below adds the post title but does not add the category specified by the user. Instead it puts it in ...
0
votes
1answer
262 views

Front end posting

This source works with image upload. Without image upload, it works, but 'redirect' doesn't work. What should I do?? Any suggestions to what the problem might be? if( 'POST' == ...
0
votes
1answer
201 views

Front end posting, not working wp_redirect with 'cannot modify header information' error

Im trying to make front end posting page but, sometime 'wp_redirect' is not working with 'cannot modify header information' error. adding data is working well but I don't know why is working well ...
0
votes
1answer
170 views

Plugin to create Posts and Forums then choose category and parent forum

I need to create a plugin for a customer that will help him create posts and forums and place them in a category and choose if it's a parent or a child forum. Just created a GitHub Repo for my files ...
3
votes
2answers
309 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
69 views

install.php Custom Taxonomy Term not being added to custom post

So I am stuck on this problem that I am facing when creating a custom taxonomy term in a install.php file. So I am running a WP multisite, and upon new blog creations, I am trying to auto create ...
1
vote
2answers
727 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 ...
1
vote
1answer
74 views

Add CPT values to Database

I am not sure if this is something easy. I have a plugin with all the functionality needed for a custom post type: Filters, navegation... I need to create a lot of posts (with taxonomies) of this CPT ...