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
2
votes
1answer
5k 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' => $retrieve_result['...
2
votes
1answer
3k 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 ...
2
votes
2answers
924 views

wp_insert_post() Callback?

After I added a post by wp_insert_post(); Any callback after I added ? I need permalink of added post. I have idea only search by title and post-type (I use custom post-type in my case), But any ...
2
votes
1answer
2k views

Add a default meta_value to new posts

I have a page template that allows users to create and update posts from the front end. I also am using 2 plugins, 1 that allows the user to rate posts from 1-5 stars and another that allows them to ...
2
votes
7answers
7k views

wp_set_object_terms() Fails to Set Terms

Okay guys, here's the scenario. I'm am trying to setup a function that will automatically duplicate a post (when published) over to another post type. So, a regular blog post is published, and when ...
2
votes
1answer
731 views

Can I trigger the publish_post hook by using wp_insert_post?

I'm writing a plugin that fetches some data from an XML file and then creates a post based on its content. I was thinking of using wp_insert_post() to publish the new post, but I have some functions ...
2
votes
2answers
2k 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 ...
2
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://...
2
votes
1answer
640 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'] = ...
2
votes
1answer
3k views

How do I Import an RSS feed as Wordpress posts without duplicates?

I have an XML feed url I am now using this code to create new Custom Post Type Posts from an rss feed in my functions.php file: /* | ---------------------------------------------------------------...
2
votes
1answer
2k views

duplicate posts when trying to update a post using the wp_insert_post.

On an empty wordpress database, I insert one sample post using the wp_insert_post. Since it's an empty database, the first post I add ends up with id 1. And I check that in the wp_posts, everything ...
2
votes
1answer
36 views

Created pages not showing up in 'All Pages' list

Due to some custom software integration, I have my theme generate some pages automatically with set templates in order to achieve the required functionalities. I do so with the following script: (...
2
votes
2answers
854 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 . ...
2
votes
2answers
191 views

wp_insert post doesn't work

Here is my script : $my_post = array( 'post_title' => "post test", 'post_date' => current_time('mysql'), 'post_content' => 'This is my post.',...
2
votes
2answers
897 views

Automatically insert php function into post $the_content

I am trying to have 2 php functions automatically inserted in every post for my CPT. The problem I am having is that even though I've found a way to add text, Im not sure how to add the php functions ...
2
votes
1answer
1k 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 ...
2
votes
1answer
1k 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 create_pages_default()...
2
votes
1answer
3k views

Inserting Hundreds of Thousands of Posts at Once

I have a project in which I create an array of 200k+ lines w/ 25 fields that run the wp_insert_post and update_post_meta. To start it processes pretty fast the slows down a lot after 10k records or so....
2
votes
2answers
422 views

Is there a faster way than wp_insert_post to add content to a blog

I've written a plugin which retrieves an xml file, parses and creates a series of short posts from the content. Although each post is very short (sometimes just a single sentence, never more than a ...
2
votes
1answer
90 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 ...
2
votes
1answer
75 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 ...
2
votes
2answers
235 views

Replace string with post_name on sidebar

I'd like to replace all {POST_NAME} 's from my text-widgets on single.php sidebar. I'm thinking of something like this global $post; $POST_NAME= $post->post_name; $sidebar = preg_replace('/\{(...
2
votes
1answer
281 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 ...
2
votes
1answer
520 views

Programmatically adding posts

I'm about to create parser which would be inserting new custom posts. So, it's pretty simple global $user_ID; $new_post = array( 'post_title' => 'My New Post', 'post_content' => 'Lorem ...
2
votes
1answer
1k views

Programmatically insert hierarchical terms & set terms for post causes glitch? [duplicate]

I am inserting an array of terms into my custom taxonomy programmatically. Some terms have parents/children. After each term has been entered, I then insert an array of posts into my custom post type. ...
2
votes
1answer
1k views

How many 'wp_insert_post' calls can be performed in one shot, in a very long 'for' loop?

I'm working on a plugin which has bulk post inserts using a spreadsheet. This spreadsheet can have multiple thousand rows, each row corresponding to a post. I'm parsing this spreadsheet, looping over ...
2
votes
1answer
425 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, ...
2
votes
1answer
387 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 [...
2
votes
1answer
196 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 ...
2
votes
1answer
2k 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 ...
2
votes
0answers
781 views

How to set featured image in wp_insert_post [duplicate]

I have a register form with upload field and when the user registers i create a new post. I need to have the uploaded picture on the featured image of the post. I have see something like this but i ...
2
votes
1answer
1k views

Organizing uploaded media with wp_insert_post() and wp_handle_upload according to time parameter

I'm retroactively creating a post with wp_insert_post() and attaching a featuring image to it. I need the image to go into the folder that corresponds to the post's publishing date. I'm using time ...
2
votes
2answers
1k views

How to add multiple product gallery images from front-end

-I am running a woo commencers shop -Users have the ability to add products using wp insert post -The product gallery multiple image upload will only add the last image to the post but in media they ...
1
vote
1answer
4k views

wp_insert_post disable HTML filter

I have input value "<iframe>....</iframe>" (param 'post_content'). When i execute wp_insert_post, function cut off my tag. How to disable HTML filter in wp_insert_post ?
1
vote
2answers
8k views

How to use wp_insert_post to update meta box?

I'm trying to use wp_insert_post to create a front-end submission form so visitors can create a post AND update the meta box fields of that post -- not the custom fields. For example, when I use the ...
1
vote
5answers
2k views

Insert Wordpress page via external (cron) script?

I'm trying to write a php script that I can run out of cron to create new Wordpress pages. Unfortunately, I can't find any documentation on how to do this. I'm using the WP scripts rather than ...
1
vote
2answers
816 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
3k views

wp_insert_post returns int(0)

if I run the following code it returns me an int(0). Wordpress creates the Post but with an empty post_title although the $name variable is filled. $postID = wp_insert_post(array( "post_title" =&...
1
vote
1answer
1k views

wp_insert_post -> post_content not showing

I have a problem with wp_insert_post. When I'm attempting to insert my post, the post_content essentially shows up as just blanks spaces. I even went into MySQL to confirm. Everything else, ...
1
vote
1answer
774 views

wp_insert_post featured image from library

I know there are a lot of posts about it, but I don't want to upload a URL image to the library, I already have the image in the library and its IP. How can I use it with wp_insert_post?
1
vote
1answer
779 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
3answers
332 views

Is it possible to create a post using a metabox?

I am trying to create a post (well, in the end, multiple posts) from a metabox using the 'save_post' hook. I executed the script once, creating 3900 or so new posts before I crawled into posts.php and ...
1
vote
3answers
7k 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-...
1
vote
1answer
105 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' ); ...
1
vote
1answer
131 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' ,'...
1
vote
1answer
87 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
2answers
392 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 ...
1
vote
1answer
403 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 ...
1
vote
1answer
951 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
2answers
630 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 ...