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
2answers
9k 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' => '...
1
vote
1answer
1k 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 ...
1
vote
1answer
1k views

wp_insert_post bulk import 500 server error

I am working on a Wordpress import tool, where I use a custom city table in my database with longitude, latitude which combine with some other text and then import by wp_insert_post(). This works ...
1
vote
1answer
201 views

wp_insert_post issue

I've got the following code in the 'functions.php' file of a wordpress theme $ppost_data = build_post( $pID, $pcontent, $pname, $ptitle, $pstatus, $ptype, $pset_comment_status ); wp_insert_post($...
1
vote
1answer
7k views

Adding custom fields (post meta) before/during wp_insert_post()

Our code base has a ton of logic that executes as the post is inserted/created. However, some of that logic depends on custom post meta. The only way I know of to add post meta to a new post is like ...
1
vote
1answer
937 views

wp_insert_post not updating custom taxonomy selected if logged in as a subscriber

Here is my Code, it works fine When i try to post data from front end if Logged in as admin, but if i logged in as a subscriber code works fine but it is not inserting the taxonomy term i select, here ...
1
vote
1answer
595 views

Inserting post, thumnail and custom fields with wp_insert_post

I just want to add custom post, a thumbnail of it and custom fields. Here is my code what I am try is to add post, thumbnail and one custom field. But I not getting the idea how to upload the ...
1
vote
1answer
436 views

add_menu_page Callback Function: Skip page content?

I want to have a menu item that will, on-click, add a page with certain arguments. In it's simplicity, I have: function av_subscribe_create_menu(){ // Create top-level menu add_menu_page( 'Add ...
1
vote
1answer
116 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 ...
1
vote
1answer
1k views

Can't get wp_insert_post to work

I'm trying to code a loop that will post articles from a SQL database. However, whenever I try to load the page I get a 500 error and nothing is showing up in the error logs. Code: <?php define('...
1
vote
3answers
1k 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 ...
1
vote
1answer
598 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. ...
1
vote
3answers
6k views

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

I have a form on 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 ...
1
vote
1answer
144 views

Do I need to deal with WordPress SQL Injection

Do I need to prepare strings against MySQL Injection when inserting into the database using a WordPress comments function such as this: $data = array( 'comment_post_ID' => $post_id, '...
1
vote
2answers
874 views

using wp_insert_post inside of custom meta box

This is kind of a unique situation. I have an invoicing custom post type that when it is marked as "paid" I want to then generate another custom post type. I have a custom meta file that handles the ...
1
vote
1answer
1k views

create parent post using wp_insert_post

how can i create php function where i can create a post in one custom post type also create a child post type, i have already create a parent post type, i.e post type "a = car" post type "b = user" ...
1
vote
1answer
718 views

wp_insert_post - How do I prevent incremental numbers on child pages?

I'm using wp_insert_post to dynamically generate child pages for a given page using a predefined array of values. The goal is to give each child page the same slug. For example, clicking "Generate ...
1
vote
1answer
833 views

After wp_insert_post(), date_i18n() and date() outputs are adjusted to GMT

I am having a very peculiar issue on a customer's server (vps). The code below works just fine on my servers. Basically, a specific unix timestamp is formatted correctly and as soon as ...
1
vote
2answers
5k views

wp_insert_post or wp_set_post_terms do not save taxonomy, but wp_set_post_terms does

I have a litlle problem. I have a custom taxonomy 'rodzaj' with value i.ex. obrazek. I use this code to add post: $postArray = array( 'post_status' => 'publish', '...
1
vote
1answer
145 views

Frontend tag edit/submit form

I would like to have a separate page to submit/edit tags. Any user can edit or submit tags. But it should be published only after admin approval. Is there any function available like wp_insert_tag()...
1
vote
1answer
2k views

wp_insert_post does not write my post_name

i tried to generate a page via wp_insert_post. That works fine except that the post_name is always written with the same value as the post_title. Here comes the code snippet: // Create homesite if ...
1
vote
1answer
2k views

preventing the duplicate wp_insert_post

Right of the bat, let me say that this is not the same question as I posted the other day ( that is duplicate posts when trying to update a post using the wp_insert_post. ) Cause, in that question, ...
1
vote
1answer
212 views

post_content sanitization / transformation process

What kind of transformation does the post_content go thru when wp_insert_post inserts a post_content into wp_posts programmatically? I'd like to be aware of this before I process 50000 recs into ...
1
vote
1answer
379 views

wp_insert_post - duration

i try to import a custom DB to the WP DB with about 2000 rows (custom post type). the problem is that the insert by wp_insert_post takes about a second per insert. Is this normal ? Is there a fast/...
1
vote
2answers
2k views

Making sure wp term relationships records are unique

Which' WordPress function is used in programmatically associating the term taxonomy IDs with post IDs? And does that function have internal mechanisms to make sure no duplicate entries are allowed ...
1
vote
1answer
1k views

using $wpdb to insert a form into a post

I am wanting to take the following form, and use $wpdb to insert it into a post. I have tried reading the class reference page INSERT rows, but I don't really know what should be referenced. I am not ...
1
vote
1answer
683 views

update_post_meta, xml parser

I'm hitting the wall for nearly two hours now, trying to figure this out. Here is the thing' I have made a xml parser to read xml file and add posts (with content) from xml: $ch = curl_init( "http://...
1
vote
1answer
3k views

Insert post in another database

I have developed a custom script that uses wp_insert_post to create new posts, however i'd like to use similar code to create the same data in another wp database. Could be this done on the fly before ...
1
vote
3answers
2k views

How to prevent duplicate posts with wp_insert_post on single.php?

I'm getting a really strange bug (WP 3.1.3). My goal is to have users create a new post simply by landing on a single post. In order to make that happen, I have the following code in my single.php: ...
1
vote
1answer
37 views

How to checked selected category checkbox when my custom post inserted from frontend

if ( isset( $_POST['save'] ) ) { if(wp_verify_nonce($_REQUEST['_nonce'], 'submit-post')){ // $userid = get_current_user_id(); $atts = array( 'post_content' =&...
1
vote
1answer
28 views

Check if post is added manually or through wp_insert_post()

I might not be thinking this right but here is my situation: I have a custom post type called events. Some of my events are imported from an API and inserted through wp_insert_post() (in a plugin), ...
1
vote
2answers
285 views

How to upload multiple image using wp_insert_post

Im using wp_insert_post to add products on the front end of a woocommerces site My current code will upload all the images but only the last image will be in the product gallery images heres my code;...
1
vote
1answer
46 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 ...
1
vote
0answers
30 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
0answers
49 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 ...
1
vote
0answers
37 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 ...
1
vote
0answers
144 views

Custom Taxonomy isn't working from frontend post submitting

hi, i am working on a video sharing site project! I have Created a Template file where people can submit their post as video! Everything was working very good, but the custom Taxonomy ponstars isn't ...
1
vote
0answers
121 views

Compare old meta with new post meta

How do I compare old meta what was already stored in the database with the new meta data what was just set by the user? For example if you want to keep track of how many times a button is clicked. ...
1
vote
1answer
581 views

Cropping an image before inserting into a post

I've got a frontend post form, and I've been using this PHP code to allow uploading an image and to insert it into a post. // image upload and attatching to post if ( ! empty( $_FILES ) &&...
1
vote
0answers
138 views

Attaching taxonomy data to taxonomy with wp_insert_post

By WP User Frontend I create a registeration form with some checkboxes, and use wp_insert_post and update_user_meta for create a new post (post type pavilion) on user registration.I want when checked ...
1
vote
1answer
968 views

keep wp_insert_post from adding duplicates

I have been struggling to import posts from an some json data. The problem is that wp_insert_post() is adding multiple versions of the posts. I was previously checking if the post existed by checking ...
1
vote
0answers
538 views

Frontend Post with JQuery AJAX to Php Issue

My problem is the following. I'm trying to make users publish custom post_type by frontend through a form like this: <form id="msform" enctype="multipart/form-data"> <fieldset id="...
1
vote
1answer
606 views

Update post meta does not serialize array

For some reason my update_post_meta() function does not accept an array. Normally the function serializes the array by itself, but now I need to do this by myself, otherwise it does not update. Could ...
1
vote
0answers
1k views

Upload featured image from front end using media-upload.php

I'm trying to use admin/upload.php to upload featured image from front end form. All I have to do is put below code in the front end form <div id="postimagediv" class="postbox "> <div ...
1
vote
0answers
1k 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 ...
1
vote
1answer
138 views

Permalink for custom post type

I have created a custom post type called job. Posts are generated with wp_insert_post(), and that works perfectly fine. My problem is that the permalinks to those posts are either wrong or I have done ...
1
vote
0answers
172 views

Post author for revision not being set on update/insert

I'm trying to programmatically update a custom-type post with revisions enabled via form, and everything seems to be working fine except the post_author field for the revision is being set to 0 ...
1
vote
0answers
948 views

Prevent Duplicate Attachment When Using wp_insert_post

I am trying to use wp_insert_attachment while using wp_insert_post. It's successfully creating the post and attachment. It have no problem if I only use the wp_insert_post function, but when I ...
1
vote
1answer
2k views

Creating a post from data returned from HTML form

I am trying to write a WordPress plugin and I have hit a bump. The Background: I have some data in a mySQL DB that I am using (each row has a unique ID and some other information I have added). I am ...
1
vote
1answer
109 views

Add CPT values to Database

I am not sure if this is something easy. I have a plugin with all the functionality needed for a custom post type: Filters, navegation... I need to create a lot of posts (with taxonomies) of this CPT ...