Questions tagged [wp-insert-post]

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

Filter by
Sorted by
Tagged with
0
votes
2answers
695 views

Add new post in existing categories using wp_insert_post

I am trying to add a new post using the function wp_inser_post in one of my existing categories, I've created a new taxonomy named categorie and in that taxonomy i have a few categories, and I am not ...
0
votes
0answers
23 views

Published page but it is page not found

I have published page with post type abc, but the page is not found. If I keep post type, then it works fine. I insert post data and publish through query: add_action( 'init', 'my_cpt_init' ); ...
1
vote
1answer
53 views

Don't insert if permalink is the same?

I have a foreach loop inserting posts. And I already have statements to check if post already exists by unique meta values. But somehow, often when site is loading slowly, something strange happens ...
0
votes
1answer
524 views

$wpdb->insert() does not insert fields

I need to insert banner data into a table wp_rdp_banners. To work with the banner data I insert the full affiliate link and also split it to save the banner url and banner image location into ...
2
votes
1answer
252 views

Can I edit the wp_post > post_content right before its inserted/updated?

I would need to apply some sort of encryption on whatever gets inserted in the wp_post > post_content, so I was wondering if there is a way, either modifying the core (rather not), or using some ...
0
votes
0answers
222 views

Programmatically create new post from a metabox button

Given a classic course-lesson structure, created by custom post types, I want to add a new empty lesson for a course, by using a simple html form on a metabox, in the course edit screen. I think I ...
0
votes
4answers
4k views

wp_insert_post custom taxonomy

I have a custom post type books and a custom taxonomy books-categories. wp_insert_post() and it works. How can i add a second taxonomy called location? This code doeasn't save my custom taxonomy ...
2
votes
1answer
129 views

Using table lock with wp_insert_post?

I'm running a cron every 5:th minute that inserts a lot of posts. Sometimes it happens that those crons are running both at the same time. To be sure that not causing duplicate posts. I would like to ...
1
vote
1answer
161 views

Could not get post ID from wp_insert_post()

function cgp_create_post($title, $name){ $new_post = array( 'post_title' => $title, 'post_type' => 'custom-post-type', 'post_status' => 'publish' ); ...
0
votes
1answer
158 views

Issue with wp_insert_post() when post_content contains links?

When I create a post using wp_insert_post() if the post_content contains an HTML link I'm getting a copy of the post_content in the <head> and the <body> of my post HTML page. The strange ...
0
votes
1answer
903 views

Inserting current user ID into Post for Author

I am trying to insert the user id of the current user when creating a custom post type. This is my code: $my_post = array( 'post_title' => $orderRequestCode.' - ' . $customerName, ...
1
vote
1answer
265 views

Creating New Page with WP_INSERT_POST Issue

I am trying to create a new page using the wp_insert_post() function as follows: $page = array('post_type' => 'page' ,'post_title' => 'The Resolution AR' ,'...
0
votes
1answer
997 views

Check for duplicate custom field value before running wp_insert_post

That is, I want to prevent 'guid_review' ACF value being duplicate by checking it before creating the post. foreach ($items as $itemKey => $item) { $myPost = array( '...
1
vote
1answer
2k 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 pressed....
1
vote
1answer
120 views

Use wp_set_post_terms() instead of wp_insert_post()

Since I use cron jobs for automation I ran into some problems with the taxonomy. Before I used the cron job, the following code used to work: $custom_tax = array( "project-type" => array( ...
1
vote
3answers
8k views

How Can I Set the Post Author of a Post I Just Created With PHP?

I'm using PHP to dynamically create a custom post, and I need the author to be someone other than the logged in user. I found this https://stackoverflow.com/questions/5759359/wordpress-manually-set-...
0
votes
0answers
22 views

Checkboxes to automatically create pages when I activate a theme

So, I want to create pages automatically on theme activation. This seems kinda easy with wp_insert_post(). The problem is: I need to select only certain pages to be created. Is there a way to do this?...
0
votes
0answers
176 views

Meta keys won't add using wp_insert_post

I have the following code, I am attempting to insert a new post with the 2 meta fields attached, the post is being inserted but the meta isn't there. Can't seem to spot anything wrong here, so what's ...
1
vote
2answers
668 views

How to auto increment post title & post slug field?

I've a custom Post Type i.e. prj and need to auto increment it's post_title (title) and post_name (slug) on post save, update regardless of the post status .. the post can never be deleted that's why ...
0
votes
1answer
1k views

Bug in wp_insert_post script and form, probably something simple I am not seeing

OK, I have been working on debugging this script for 2 and a half days now and am coming up empty. Basically, this is a front end form that will insert posts based on the script that I wrote for it at ...
1
vote
1answer
2k views

Get data from wp_editor()

I can use wp_editor() function for add custom post use wp_insert_post() function (with post_content parameter) in my plugin. I need to can be saved data from wp_editor() function. How can i get ...
1
vote
0answers
43 views

When User Meta amended update Title and Slug of Post programatically

I have this code below which works perfectly, i.e. when adding a new User a post is programatically created in my CPT. add_action( 'user_register', 'add_member_employees' ); function ...
1
vote
1answer
576 views

wp_insert_post is not creating revision in database

I am creating custom frontend post submission form. I am using wp_insert_post for creating new post. The function is working fine but it is not creating the revision record in database. Following is ...
2
votes
0answers
59 views

Is there a better way to programmatically insert content into a page?

During activation of the plugin I'm writing, I insert a custom page. I can add post_content using the wp_insert_post command, which seems like a reasonable way to add a limited amount of content. For ...
0
votes
1answer
72 views

how to call other plugins once custom post has been inserted

i built custom script to import woocommerce product using (wp_insert_post) and i want to call other plugins to insert their data to each new products to db for example: after inserting product if i ...
0
votes
1answer
199 views

Why insert post function do not set the modified author without administrator panel?

I am have a front-end new post and edit post forms. I'll using the <?php wp_insert_post( $post ); ?> Everything is all right here. If any editor or admin modified any author posts on front-...
1
vote
2answers
1k views

Contact Form 7 to featured image

I am trying to retrieve a file uploaded in the front-end with contact form 7 and assign it to a featured image custom post type. Heres is my code so far : function form_to_post( $posted_data ) { ...
1
vote
1answer
326 views

WPML - Set language of inserted post

I have a contact form 7 on the front-end which creates a new custom post everytime it's filled. Everything is working fine but I don't understand how to set the language of this post (currently it's ...
0
votes
1answer
195 views

wp_insert_post wrong post type [closed]

Much like this question, I'm having trouble with wp_insert_post causing recursive post adding. I do, however, have implemented a page type check - the problem is the inserted post always gets added as ...
3
votes
1answer
1k views

Posts added with wp_insert_post are moved to trash automatically

I've got a script that loops through some data and automatically creates some posts. foreach($data['title'] as $title) { $my_post = array( 'post_title' => $title, 'post_content' =>...
0
votes
0answers
66 views

How to insert post 6 times after user register like ask.fm

I have a question and answer site like ask.fm. On ask.fm when you register a new account you found that you have 6 questions (posts). I need to make the same. Whenever a user registers I need to add ...
1
vote
1answer
4k views

Create Page With wp_insert_post() and AJAX

I've been trying to figure out how to create a post (or any custom post type) with wp_insert_post() and AJAX...so far to no avail. What I hope to achieve: Any user (not just logged in ones, I don't ...
0
votes
0answers
486 views

Insert Multiple Posts from JSON Results

I am working on a custom function to insert posts from a JSON feed. The JSON feed produces results as it should, but I am unable to get the wp_insert_post() function working properly, I assume ...
0
votes
1answer
959 views

wp_insert_post() creates duplicates with 'post_status' => 'publish'

I am trying to add posts of a custom post-type in bulk from a .csv file. Everything works except that it adds the post twice. They are exactly the same in the database except one has author 1 and the ...
1
vote
0answers
38 views

Auto-create a post with last 10 images in WordPress directory

I want to create something to help me auto-create a post with 10 last images hosted in some directory (in my server or WordPress), this code I found helps to post an image but not many images if ...
0
votes
1answer
381 views

get post id from wp_insert_post for get_template_part

This is my code: $my_post = array( 'post_type' => 'theposttt', 'post_title' => 'test', 'post_content' => '', 'post_status' => 'publish', 'post_author' => 1 ...
0
votes
1answer
130 views

Programmatically create a post once a day

By following this howto, I wanted to create programmatically a post, once a day. Accordingly to the author, the next line will check if a post with a given name already exists: if( null == ...
0
votes
1answer
312 views

Adding user meta to post meta wp_insert_post() not working

i'm trying to add a users meta field to a posts custom field when inserting a post using wp_insert_post() but it isn't working. I've tried replacing the $branch with a simple string and it works but ...
0
votes
0answers
47 views

Creating a frontend blog post form for logged in users only

I recently tried to make a form for users that are logged in to be able to add a post from the frontend to their profiles. The problems I have found are the following: ANYBODY can post from it, even ...
0
votes
1answer
982 views

Returning all values from foreach in function php [closed]

i have a foreach within a function where i want to return all the values and then store this in a variable to add to the post_content in a wp_insert_post function. I've tried echoing all the keys ...
0
votes
1answer
940 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: http://bluepresley.com/farmerfinder/?dir-item=dance-...
0
votes
1answer
581 views

Generate CSV file and add data as a new wordpress custom post

I have a page where i'm using a button to generate a csv file from data being looped from an array, which when clicked is then automatically emailed to a user. I also want the data to create a new ...
0
votes
1answer
1k 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: http://voodoopress.com/including-images-as-attachments-or-featured-image-...
0
votes
1answer
201 views

How can I automatically add a post with Latin characters?

I would like to add a post in Wordpress with cURL (php) and I have this string to add as a content: $text = "Trovato, assieme a Massimo e Anna, in una cantina di Via Barrili a Milano, con un'...
0
votes
1answer
2k views

$user_id = wp_insert_user( $userdata ) Not working no errors

Below insert of new user does not work. I have no idea why not. There are no error messages send to debug.txt or to screen. I have also checked a bunch of thread about this insert. But it seems my ...
2
votes
2answers
1k views

Create posts without login from frontend

I am new to WordPress development ,I am using wp_insert_post() to create posts from front end, This function works fine when I have already logged in but I need to implement this without any login . ...
-1
votes
1answer
2k views

Using wp_insert_post to create custom posts with ACF image field

I've been searching for an answer for days now. I have a project where I need to create a front-end form that will request a bunch of information and use it to create a post draft for the client to ...
1
vote
2answers
939 views

wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated

So, I have a plugin that uses Ajax to dynamically build the post content piece by piece for a custom post type. Once the user has build their page, they hit Update/Publish and Ajax sends the entire ...
3
votes
1answer
3k views

Slash is being stripped in my post_name when using wp_insert_post

I want a permalink with slashes : e.g. http://mysite.com/keyword1/keyword2/mypage.html I have put it in the param "post_name" in wp_insert_post but the slashes are stripped, so the result is http://...
12
votes
1answer
5k views

How to set post slug when using wp_insert_post();?

My theme uses a custom template to render some contents. To use this template, I'm hooking into after_switch_theme to create my own page after the theme is activated, and then assign this template to ...

1 2
3
4 5
8