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
9 views

Update post_meta post_name with the post ID from wp_insert_post after user register

I'm creating a function that creates a page for a user when they register. The post created sits within a certain category. These are standard posts NOT custom post types. After the post is created I ...
0
votes
0answers
27 views

wp_insert_term or wp_set_object_terms not working in register_activation_hook?

I am creating a couple of CPTs and assigning a term to these posts. The posts are being created properly, but the term isn't being assigned to the posts. I tried using tax_input, wp_set_object_terms. ...
0
votes
1answer
26 views

Front end post submissions do not get submitted in the category

If I submit the post after choosing a category the post doesnt get submitted and instead it takes me to the category page i have selected.However if i delete the fieldset "category" and fill the form ...
0
votes
0answers
41 views

How to update posts via PHP in wordpress

I need to do the exact same what "update" button in the WP Backend does, but with PHP (and I know it has been asked 10'000 times, but the situation isn't that trivial :( ) wp_update_post should be ...
1
vote
0answers
102 views

Issue with wp_insert_post and post_content field error Could not update post in the database

I'm having issues creating an import / caching script to be used within a WordPress site. This feed comes from a single text file that is then parsed and returned as an array. When running through ...
0
votes
1answer
54 views

duplicate entries in database while using save_post or wp_insert_post

Here is what I am trying to do - I have created a custom table in the database and I am trying to enter data into it everytime a post is created. The database-entry needs to happen ONCE AND ONLY WHEN ...
0
votes
2answers
36 views

Wordpress implode & wp_insert_post question

Just a few days ago I've started working on my new wordpress based website. I have a plugin which provides a Cars Database. I want to auto-fill my custom fields and taxonomies by taking info from ...
0
votes
0answers
25 views

Setting title in the front end

I am trying to set up posting from the front end. Everything works, but I cannot get the title to set.. Part of code: (Some validation is done beforehand) $title = "abc"; // ADD THE FORM INPUT ...
0
votes
2answers
56 views

generate unique slug while inserting post

How can i create unique slug while inserting a new post.. I know i can query posts and compare the records to create unique slug but I want to insert a post with unique slug at the same time. Lets ...
0
votes
1answer
53 views

Can't get post ID using wp_insert_post_data

I have 3 custom fields as shown below. I want to use them to generate the title when I save/publish... etc The code works if I insert the post id as a number but not like this... function ...
1
vote
1answer
39 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
1answer
29 views

Generate slug and meta data if meta field is empty

I am creating a current vacancies feature in a client site, and am struggling on one area. I want to have a slug generated from a reference number, rather than the post title. This, I have set up. ...
1
vote
0answers
54 views

wp_update_post adding a -2 to the post slug

I've recently created a php file that is creating posts using the wp_insert_post function. This is working great and its inserting the post as it should do. I am leaving out the post title as I want ...
0
votes
1answer
113 views

Bulk insert posts is really slow and skips entries

I'm writing a plugin to parse a bunch of XML files with the NewsML standard and insert them into the database as custom post type. Everything works fine and as intended, but especially at the first ...
1
vote
2answers
134 views

save_post action to include wp_insert_post_data filter, gathering meta field info & prevent infinite loop

Im trying to change the title of a post, but I want to include info from a meta field, the value of which isn't saved to the database until after the posts has already been saved. Other than this one ...
2
votes
1answer
82 views

Visual Editor - Colorize Shortcodes

I want to highlight shortcodes in the WordPress visual editor in a specific color. E.g. I Have the following Shortcodes [shortcode1] Some text [/shortcode1] ... [shortcode2] Some text ...
0
votes
0answers
144 views

Check if Post Id exists, Insert post if doesn't, and update meta status 0 if does

I was looking for an answer and found this example: $postTitle = $_POST['post_title']; $submit = $_POST['submit']; if(isset($submit)){ global $user_ID, $wpdb; $query = $wpdb->prepare( ...
0
votes
1answer
33 views

Add a image to a post published on a CPT from the front-end

I created a CPT with a page where you can add posts from the Frontend. This is the code in the fuction.php: // Hook into the 'init' action add_action( 'init', 'register_cpt_promociona', 0 ); if ( ! ...
0
votes
1answer
70 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 ...
0
votes
0answers
114 views

How to retrieve data sent via wp_remote_post() from another WordPress site?

So, I am using wp_remote_post() on site A to send data to my server B, then use this data to create a new blog post each time request is sent. Here is the scenario: 1- Site A: send data via ...
0
votes
0answers
19 views

How to pick up featured image from set of pictures

I'm trying to create front end form for posting. The following questions are concerning me so bad. How can I set a featured image? I tried set_post_thumbnail($pid, $newuploadid); but nothing happend. ...
0
votes
1answer
109 views

Insert attachments from front end form

I built a front end form but suddenly cannot submit my image attachments. Refer to these articles which do not get it done: ...
0
votes
1answer
102 views

Set default Custom Post Meta Value

I've tried almost anything and just can't get this to work. I have a custom post type with a custom meta field and I want a default value to be added on when the Publish/Update/Save button is ...
0
votes
1answer
48 views

Manually insert post into MULTISITE database: Need to specify the TABLE

I need to manually insert a post into multisite database. I'm using the variables listed here: http://codex.wordpress.org/Function_Reference/wp_insert_post ...and have been able to insert a post into ...
2
votes
1answer
75 views

Efficient way to save a lot of meta data

im currently developing a plugin that will read an external xml, and convert the data to a custom post type. Each post needs around 50-60 meta_fields. Right now im looping through each piece of needed ...
0
votes
0answers
64 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
40 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
156 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
15 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
1answer
103 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 > ...
3
votes
0answers
268 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
38 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
184 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
47 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
8 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
677 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
63 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
64 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
50 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
52 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
164 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
358 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
185 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
62 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
162 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
65 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
80 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
83 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
22 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
87 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 ){ ...