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
1
vote
1answer
96 views

Add file while inserting post

Is it possible while adding post through wp_insert_post also upload images to this post from url.
1
vote
0answers
295 views

Wp_Insert_Post: Do not insert if the title exists [duplicate]

i've made a simple code here to fetch and insert the last news from a feed Rss: <?php // Get RSS Feed(s) include_once"wp-config.php"; include_once"wp-load.php"; include_once"wp-includes/wp-db.php";...
1
vote
1answer
2k 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 error....
0
votes
1answer
489 views

wp_insert_post works, but the post isn't visible in the admin post list or front end

I am trying to create a page on a site during plugin activation. The code is working without error and the function call returns a post ID, but when i check the list of pages in the admin area there ...
0
votes
2answers
72 views

Is there anything special I have to think of when setting post_date_gmt when inserting a new post?

I'm inserting information from a user into a custom post type. $current_user it a user-object. Is there anything special I have to think of when setting post_date_gmt when inserting a new post with ...
0
votes
2answers
14k views

post_status => publish not working

I have a front end form that let users submit a post. This is how i store the data when a post is submitted : if ( isset( $_POST['submitted'] )) { $post_information = array( '...
0
votes
2answers
243 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
1answer
2k 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
3answers
1k views

Conditionally set post_content in wp_insert_post

Is it possible to conditionally set the post_content in wp_insert_post? Im using a foreach to add multiple pages at once: foreach ($create_pages as $new_page) { $add_pages = array( '...
0
votes
1answer
397 views

Allow unfiltered HTML for not logged in users when saving a post

I'm using this code: $var1 = $_GET["t1s2ninput"]; $var2 = $_GET["t1s2pinput"]; $new_post = array ( 'post_title' => 'Title <dl class="variation"> <dt>Variation: </dt> <...
0
votes
3answers
1k 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 ...
0
votes
2answers
9k 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.
0
votes
2answers
3k 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 wp-includes/...
0
votes
1answer
3k 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
7k views

How to update post parent?

I have an array of image id's and i want assign them to the specific post: foreach ($image_ids as $image_id) var_dump(wp_insert_post(array('ID' => $image_id, 'post_parent' => $new_post_id),...
0
votes
1answer
439 views

Inline style HTML attribute is being stripped from all elements of a post

I am attempting to publish HTML generated from an external party within Wordpress, but I am getting very inconsistent results with style attribute on all HTML elements, in that if I programmatically ...
0
votes
2answers
154 views

add_user_meta allows multiple clicks and inserts more than 1 value

I've just checked a double click on my form that inserts new user meta, which actually inserted it twice! The problem is, I actually need the values to be non-unique so I can insert multiple times. ...
0
votes
1answer
130 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-...
0
votes
1answer
82 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
26 views

Remove all removed pages from wordpress

I am creating a plugin in wordpress and the thing I am trying to do is to create pages with code using wp_insert_post. After creating each page and removing all of them the new page with the same slug ...
0
votes
1answer
597 views

Where to call wp_insert_user() and wp_insert_post() from?

I'm trying to perform a batch insertion of multiple users and posts using the wp_insert_user() and wp_insert_post() functions. The problem is, I can't find any clear instructions as to where I should ...
0
votes
2answers
379 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
2answers
3k views

wp_insert_posts Fatal error: Maximum function nesting level of '100' reached, aborting!

I'm having a weird problem I have written the code as below: add_action('save_post', 'save_post_func'); function save_post_func(){ include_once(ABSPATH . WPINC . '/feed.php'); $rss = ...
0
votes
2answers
249 views

Is there a way to fire other functions from wp_insert_post

I am creating a new post using the wp_insert_post function. Here's what that code looks like: $new_post = array( 'post_title' => $newtitle, 'post_status' => 'publish', ...
0
votes
1answer
9k views

Insert Post using Ajax

I'm using the following code to submit a form from a Wordpress page. <script type="text/javascript"> $j=jQuery.noConflict(); $j(document).ready(function(){ ...
0
votes
2answers
1k 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 ...
0
votes
1answer
1k 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
6k 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 ...
0
votes
1answer
458 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 ...
0
votes
2answers
451 views

Is it possible to add posts and images (auto resize) for custom post types with a script?

I have a specific need to import many post with featured images into a custom post type. The issue is, I need this to be a script because it runs off of another system that collects all the data. I ...
0
votes
1answer
977 views

wp_insert_post alternatives for faster process

I'm using wp_insert_post to generate posts for my site. Initially, everything works fine and it was very fast. When the number of posts accummulated to about 3000, it became very slow and now i almost ...
0
votes
1answer
37 views

WordPress hook which triggers on post import

I am adding few meta fields for product post type using wp_insert_postaction and it is working perfectly. But I have to trigger my function upon product imports as well as this action is not firing ...
0
votes
1answer
57 views

WP-CLI --meta-input error: Warning: Invalid argument supplied for foreach()

I'm using this code to import posts from a csv file, which works great except for the meta_input (custom fields) while IFS=$'\t', read -r col1 col2 col3 col4 col5 col6; \ do \ wp post create \ --...
0
votes
1answer
52 views

How to handle new post from API request?

I feel silly for even asking this, as it seems like it should be very straightforward but I'm having a hard time finding this information. Goal: Make a POST request to the WordPress API with new post ...
0
votes
1answer
95 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
2answers
266 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
1answer
132 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 ...
0
votes
1answer
256 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
299 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
369 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
2answers
259 views

Auto-generated posts not showing in backend (but being counted!)

I have a custom post type with a custom backend page. I'm creating posts of that type using this code: $postarr = array( "post_type" => "product_settings", "post_status" => "...
0
votes
1answer
1k 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 ...
0
votes
1answer
366 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 ...
0
votes
1answer
56 views

How to handle this specific case of custom post type?

I'm working on a WP plugin called WP SoundSystem. It's a plugin designed to run on a "music" website : it handles artists, tracks, albums, playlists... through custom post types and tools. You can ...
0
votes
1answer
88 views

Insert multiple posts as parent of the first

I am trying to create some posts using the wp_insert_post. I want all the posts to be parent of the first. I tried different approaches with no luck. Does anyone have any idea how this could be done? ...
0
votes
1answer
47 views

Create one-use post dynamically, add to main query, do not insert post (user profile view)

I'm trying to create my own user profile pages. When someone requests example.com/profile/username, I want to query the user tables for a user with username (= slug) and display the result. Ideally, ...
0
votes
1answer
45 views

Creating posts from API data, how to identify posts already imported?

As the title says, I'm using an API to fetch some data which is used to create CPT posts, and need to identify items returned from the API which have already been inserted as posts. The API returns ...
0
votes
1answer
770 views

Programatically inserted posts not showing in Posts Table

I'm trying to insert a custom post through a form. It's a brief post, most content are custom meta fields updated with add_post_meta. So far, post inserting is working fine, except for a detail. This ...
0
votes
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
1answer
4k views

Fatal error: Call to undefined function wp_insert_post()

So I have a form that has makes the action jump to another php page. There my php code tries to upload a post. I get the following error: Fatal error: Call to undefined function wp_insert_post() ...