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
66 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
1answer
797 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
3k 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
252 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
221 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 ...
6
votes
3answers
9k 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
183 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
116 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
78 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
564 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
401 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
159 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
898 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
445 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
229 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
443 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
106 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
232 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
158 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
137 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 ...
-1
votes
1answer
581 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
5k 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
519 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
386 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
119 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
145 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
218 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
301 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
117 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
606 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
1k 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
253 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
190 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 ...
4
votes
3answers
829 views

Running WP Cron on specific local time

The scenario is to run insert_post function every midnight (00:00) of local time. Must run daily on weekday. function add_daily_task(){ if((date('l', time()) != 'Saturday') || (date('l', time()) ...
0
votes
1answer
74 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
1answer
76 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 ...
1
vote
1answer
178 views

HTML Entities in Post Title

I'm inserting posts into wordpress using a script which is loaded through CRON. Before inserting each post I am checking whether the post with the same title exists or not. Below is the snippet I'm ...
1
vote
1answer
329 views

wp_insert_post not updating custom taxonomy selected if logged in as a subscriber

Here is my Code, it works fine When i try to post data from front end if Logged in as admin, but if i logged in as a subscriber code works fine but it is not inserting the taxonomy term i select, here ...
0
votes
1answer
113 views

Post content not showing some content

I'm inserting posts by wp_insert_post function. It works like first a post is created to get its id then an image is attached to that post id. I attach images by media sideload function. Here is the ...
0
votes
0answers
56 views

Omitted Content After Post-Publish Insertion

I have a string that contains $thehtml but whenever I insert it manually into a custom post it appears that wordpress alters/strips down the html.... I've already tested/outputted $thehtml string in a ...
1
vote
1answer
2k views

wp_insert_post or wp_set_post_terms do not save taxonomy, but wp_set_post_terms does

I have a litlle problem. I have a custom taxonomy 'rodzaj' with value i.ex. obrazek. I use this code to add post: $postArray = array( 'post_status' => 'publish', ...
0
votes
2answers
3k 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; ...
2
votes
2answers
2k views

Adding post thumbnail in programatically inserted post

I want to insert post programatically so here is the code to add one: global $user_ID; $new_post = array( 'post_title' => 'My New Post', 'post_content' => 'Lorem ipsum dolor sit ...
2
votes
1answer
146 views

How To Disable Comments On New Page

I am writing a plugin that upon activation, it creates a few new pages. On these pages, I want to disable the comments option. I am adding the new pages via the code below: $page['post_type'] = ...
0
votes
2answers
61 views

Add Page With Parent ID

I am writing a plugin that upon activation creates a set of pages. The first page that I create I want to be the parent of the rest of the pages that are added. For some reason, this is not working. ...
0
votes
1answer
175 views

Import Dummy Content and Post Thumbnails

I am setting up a small dummy content plugin. What I would like to do is import several posts using wp_insert_post. Then I would like to import several images using wp_insert_attachment and then ...
0
votes
2answers
338 views

Yet another wp_insert_post infinite loop. What is wrong?

I am writing a plugin that enables subscribed users to submit posts of a custom type, and I am trying to implement this feature via shortcodes. Now the problem is that instead of inserting one post, ...
0
votes
1answer
325 views

Alternative to new_to_publish Hook for Custom Statuses

I am looking for the right hook to use for sending out an email notice when a post is inserted. However, I am using custom statuses (in this case 'holding') which doesn't seem to get hit with the ...
1
vote
1answer
176 views

post_content sanitization / transformation process

What kind of transformation does the post_content go thru when wp_insert_post inserts a post_content into wp_posts programmatically? I'd like to be aware of this before I process 50000 recs into ...
1
vote
1answer
2k views

insert post & Upload post thumbnail from the front end using ajax

i have searched & searched for an explenation and have found some answers that seem to be working for other people on this topics but i havent been able to get working. This is my "form" <div ...