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

-1
votes
0answers
10 views

wp_insert_post 500 server error

I need some help, im trying to do a wp_insert_post with a htmlform (php and wordpress). I keep getting a 500 server error and i dont understand why, can you please help me? (the prints and echoes is ...
0
votes
0answers
15 views

Insert post programmatically and decide to tweet or not to tweet

I am inserting a new post using wp_insert_post() and want to be able to decide if this post gets tweeted or not using the WP to Twitter plugin. First, I create the post, like so: $newpost = array( ...
0
votes
0answers
15 views

publish new post via the front-end and adding to it a custom taxonomy term

I have a form which is adding new posts via the front-end using the function wp_insert_post, my problem is when i'm trying to attach the new post to a custom taxonomy term. this is my code: ...
0
votes
0answers
8 views

Update post else insert post

I'm trying to insert posts from a CSV. This is all working fine, and also meta boxes are getting inserted. But the update functionality isn't working, and I just can't seem to get it right. I know I ...
0
votes
1answer
23 views

How to use `wp_insert_post()` and `get_permalink()` functions?

I'd like my script to post an article to Wordpress site automatically. Looks like Wordpress's wp_insert_post() function is what I need. But if I would include wp-includes/post.php file into my script ...
0
votes
0answers
5 views

Insert post from front end, need to update it for it to show on page

I have this form and in my functions I do a wp_insert_post where I insert the form values into custom fields on my custom post type. Everything is working fine, the post is Published and all the data ...
0
votes
0answers
12 views

wp_insert_post with advanced custum fields repeater

at the moment i stuck a little bit at my new wordpress project. The basics are: The user can create nutrition plans and there he can add some recipes, so i need to build a relationship from user > ...
2
votes
0answers
72 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
23 views

Adding post date will not insert new post

$postdate = '2010-02-23 18:57:33'; $postData = array( 'post_title' => $attachment->post_title, 'post_type' => 'post', 'post_content' => $image_tag . $attachment->post_title, ...
0
votes
1answer
68 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
31 views

Why cant I add a custom post type to a custom taxonomy?

I am trying to assign a custom taxonomy to a custom post type with wp_insert_post function. $args = array( 'post_type' => 'custom_post_type', 'post_title' => wp_strip_all_tags( ...
0
votes
0answers
7 views

WP send email on new post not on revision [duplicate]

I have something like this for my custom post type: function send_property_email_notifications( $post_id, $post, $update ) { global $wpdb; global $post; $slug = 'property'; // If this is just a ...
0
votes
2answers
117 views

Programmatically add terms to custom post types

What I want to do is assign a hierarchical term to a custom post type: function create_frontles_posts() { $x = 1; do { $post_id = wp_insert_post(array( 'comment_status' => ...
0
votes
0answers
30 views

Cannot save json in wp_insert_post

This is my code. $offer_name doesn't get saved. $obj = json_decode($result, true); $i = 0; foreach($obj['response'] as $item) { for($i=0;$i<=$item['count'];$i++) { $offer_name= ...
0
votes
0answers
38 views

wordpress form processing to custom post type not working

I'm trying to insert a custom post type for a multiple image upload form. The below code is the form processing. The page is blank when i submit the form. Where did i go wrong? <?php ...
0
votes
1answer
20 views

insert image with custom post type

When processing the form i want the values to be inserted into the custom post type products. Here is what i have done so far $art_title = $_POST['art_title']; $i = 0; foreach($art_title as ...
0
votes
0answers
17 views

How to insert new user to database when post created

I'm trying to use wp_insert_post_data filter to insert a new user into the database when a new post is created. This is the code I have function post_add_user( $data , $postarr ) { $postid ...
1
vote
0answers
97 views

Create post using Ajax

I want to create post using Ajax . I had followed the process from Insert Post using Ajax But I couldn't make it work. Here is what I did. Please see what I did wrong as I am just a learner. EDIT ...
0
votes
2answers
134 views

upload images on front by user using form

I'm using a form on my website using wordpress to allow users to create posts. It works perfectly fine, I'm abble to assign the posts to a custom post type, add Advanced Custom Fields, content, ...
0
votes
1answer
55 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 ...
0
votes
1answer
23 views

Add image to post from external URL

I'm doing a plugin that can retrieve media from external APIs, and when I click on it (on the admin), it insert a new post with the media, its caption, etc. So, now, I'm inserting a new post on click ...
0
votes
1answer
32 views

wp_insert_post insert a post but return 0

I am trying to insert a page of a theme with after_switch_theme hook .Now when I set the page_template then it insert the post but return 0. Is there a way to insert a page with specifying a template ...
0
votes
2answers
44 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
0answers
39 views

Why doesn't wp_insert_post script works?

$user_id = $_POST['post_user']; $get_user = get_user_by('id', $user_id); $post_title = $_POST['post_company_name']; $post_hidden_section = $_POST['post_hidden_section']; $post_hidden_category = ...
0
votes
0answers
39 views

wp_insert_post keeps returning a post_parent id

I'm doing this: $postarr = array( 'post_status' => 'publish', 'post_type' => 'attachment', 'post_title' => $name, 'post_content' => '', 'post_author' => 2 ); $post_id = ...
0
votes
0answers
16 views

adding a log row log table, when the draft post publish

i wrote some codes, about wpdb update query. but update_post meta works fine but, wpdb update query doesn't. where am i wrong ? here is the code ; add_action('publish_post', ...
0
votes
0answers
58 views

Get Custom Field Value of a $post_id on wp_insert_post Action in functions.php

I have this code in the functions.php file which emails the post content to the admin every time a pending post is added to the database: function send_email_on_pending_post_creation( $post_id ){ ...
1
vote
1answer
50 views

Email Post Attachment on wp_insert_post Action

I have a frontend form that uses wp_insert_post() to programmatically insert posts into the site with "pending" status. I'm also using insert_attachment() to attach the submitted file to the post. ...
0
votes
0answers
41 views

Inconsistent post order using wp_insert_post

I am retrieving a consequent (~4000) number of posts from a database that I want to save to my WordPress database. I am inserting them this way: include("wp-config.php"); $con = ...
0
votes
1answer
64 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, ...
1
vote
1answer
115 views

wp_insert_post() getting slower the more posts

I have written a bulk import script where I import posts with the wp_insert_post() function and add 1 meta value and 1 term to the post. I have done 6 times of 7000 posts now, but for some reason the ...
0
votes
2answers
56 views

wp_insert_post at same time as saving post results in 502 Bad Gateway

I'm currently trying to create/update one post while also saving the current post that I'm on. It's all happening here: add_action('save_post', 'wysiwyg_save_meta'); function wysiwyg_save_meta(){ ...
0
votes
1answer
98 views

How can I programmatically save data into custom fields that contain serialized data?

I purchased a theme from themeforest recently that has a custom post type. Here is a link to a page that's been created with the custom post type: ...
1
vote
2answers
491 views

How do I programmatically add items of content to a custom post type?

I have a custom post type to which I'd like to programmatically import data. I have followed these instructions and these, and I can easily do it for WP typical pages and posts. However, my custom ...
0
votes
1answer
24 views

Changing wp_insert_post() location

I know that wp_insert_post() insert posts into wp_posts table. I want to change that to insert posts into lets say wp_posts2. Can I do that? I need to do this because I don't want to mess data from ...
0
votes
0answers
49 views

save_post action not firing due to old page_template meta data

I have some functionality hooked to the save_post action that wasn't working for a user on a particular WordPress Page. After some digging I found that wp_insert_post() was returning before getting ...
0
votes
0answers
61 views

add_post_meta from front end form

I am trying to add new post and meta data from the front end. I have a form and a custom post type named 'parts'. Looking for the easiest way of adding meta box and passing a value from the front end ...
0
votes
1answer
240 views

Create new Wordpress post [wp_insert_post] based on results of a WP_Query

I have a a page where users can filter a list of custom post-type posts based on the "Ultimate WP Query Search Filter" plugin. Results are passed to a div on the page using AJAX from there users can ...
0
votes
0answers
35 views

Creating multiple functions for front-end forms

I have the following situation (which I simplified for didactical purposes): page-books.php: <form> <input type="text" name="title" /> <input type="text" name="sinopsis" /> ...
1
vote
1answer
826 views

How I upload, save and set a featured image from my frontend?

I have a form in 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
1answer
571 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 = ...
0
votes
2answers
470 views

Insert data from custom created PHP page into wp_postmeta table

I am working with a Wordpress site and have created a custom page in /home/planmyme/public_html/php/ with the name response.php. On this page I am getting a value to insert in the wp_postmeta table ...
0
votes
1answer
405 views

WordPress Frontend Post Form (Bootstrap Modal) Not Creating Post

I have a form in a separate PHP file in the theme directory and it's being included in the sidebar of the main page template. The form is inside a Boostrap modal. I've been trying to use this code to ...
0
votes
1answer
99 views

wp_insert_post Only creates draft

When I call wp_insert_post() with a post status, it only creates posts with "Draft" status. I've tested it with WordPress built-in statuses and my custom post statuses. But it only creates Draft ...
0
votes
2answers
268 views

post_categories array using variable

When using wp_insert_post can I do something like: $categories = '1,2,3,4,5' ...and then... 'post_category' => array($categories)
0
votes
0answers
60 views

wp_insert_post questions

I'm trying to add posts using wp_insert_post, but a few issues occur. First the code: function importposts() { $fh_import = @fopen( dirname( __FILE__ ) . '/importposts.txt', 'r' ); if ( ...
0
votes
0answers
65 views

wp_insert_post hook not being called with wp_publish_post or wp_insert_post?

I have a plugin that converts hashtags (any text that starts with #) into Wordpress tags. It's working great when I manually create a post via the Wordpress dashboard, but doesn't work when I ...
0
votes
0answers
74 views

Grab the Post ID created by wp_insert_post($post)

Okay apparently there have been at least a few people already asked this question (1, 2), but none seems to get the right answer... wp_insert_post() and the following update_post_meta() & ...
0
votes
1answer
55 views

Save the Post ID from wp_insert_post($post); into a text file?

I'd like to create some posts using wp_insert_post and then save the created posts' Titles and ID's into a text file for future reference. How could this be done?
0
votes
1answer
53 views

importing table data to custom post type

i'm trying to import data from table to custom post types below is the code i'm using but this $row['Title'] return nothing ... if i hard code it works $rows = $wpdb->get_results( "SELECT * FROM ...