Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

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

3
votes
1answer
178 views

Speeding Up Bulk Post Creation - wp_insert_post & update_post_meta

I am creating posts (variable products) using (wp_insert_post) function. An Example, I have 9 colors, 9 sizes. Which makes 9×9 = 81 total variations for 1 product, which is 81 times below function to ...
2
votes
1answer
403 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
194 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
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 ...
1
vote
1answer
25 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
1answer
43 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
18 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
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
45 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
127 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
100 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
0answers
137 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
0answers
524 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
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
0answers
168 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
917 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 ...
0
votes
0answers
32 views

get_page_by_title() not working as expected

I'm looping through an API with jobs and creating new posts from it like this: //fetch jobs and loop through them... // check if post title exists, if not add it. if ( ! ...
0
votes
0answers
21 views

Use a cron job to automatically create posts based on dates

I have a custom post type called cpt1. I need to run a function that on a daily base Loops through cpt1 and then check the dates. This is done by using cron job to trigger. Within this loop ...
0
votes
0answers
19 views

Generate post content from meta fields

I have a custom post type (match). Each posts on this CPT has one ore more custom fields. Is it possible to automatic generate the 'post content' with the value of my custom fields on these posts? ...
0
votes
0answers
20 views

Create posts by any logged in users

I want to allow logged-in any users to create posts. For this purpose I created a form <form> <div class="form-group"> <input type="text" class="form-control" id="...
0
votes
0answers
39 views

Deleting custom post type from external API via wp_delete_post

I've been working with an external API to pull in data and create what's essentially a job board via custom post types with wp_insert_post. My concern is that once these jobs/custom posts are removed ...
0
votes
0answers
21 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' ); ...
0
votes
0answers
35 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
0answers
21 views

How to set canonical url for wp_insert_post created post?

I creating posts with wp_insert_post, and I want set for these posts canonical urls... How can I do this? Any idea is it would be fine. In a perfect world I could use an option for this in my array......
0
votes
0answers
162 views

Cannot add posts via wp_insert_post(). Gets database error

I am trying to add a post via an external file, but I keep getting an error: WP_Error Object ( [errors] => Array ( [db_insert_error] => Array ( [0] => Could not insert post into the database ...
0
votes
0answers
22 views

how to use wp_category_checklist() to insert via wp_insert_post()

I'm wondering in which way i can process the ticked categories and submit them into the array: $my_post = array( 'post_title' => $title, 'post_content' => '[play_video url="'.$link.'"]', '...
0
votes
0answers
20 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
111 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 ...
0
votes
0answers
156 views

Is it possible to use 'wp_insert_post' function within a for loop?

I want to insert as a custom post type some data fethced from an API, I store that data and then pass it trough a for loop, then I use the loop data to create an array to pass it to wp_insert_post ...
0
votes
0answers
53 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 ...
0
votes
0answers
260 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
0answers
26 views

Posting to list item with OptionTree

Having a bit of an issue trying to get this to work. I am submitting a form which is entering data into meta fields of a custom post type, so I have wp_insert_post set up and working, entering text ...
0
votes
0answers
33 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
0answers
19 views

automatic creation of custom post type articles

I have an external database besides WordPress which has a table with genealogical data. In WordPress, I have created a Custom Post Type (CPT) and for these genealogical records. There is also a ...
0
votes
0answers
734 views

500 error after wp_insert_post

The insert post works correctly, but then afterwards get a 500 internal server error for some reason, tested on a simple localhost site on my computer but error does not occur. :- global $user_ID; $...
0
votes
0answers
353 views

switch_to_blog($blog_id); still writing to main blog

I'm creating new blogs (wpmu_create_blog) in a for loop, What I am trying to achieve now is to insert posts into each newly created blog using switch_to_blog. The problem is wp_insert_post still ...
0
votes
0answers
801 views

Call to a member function insert()

I did a POST form and try to sign in to the Wordpress database is showing this error. Fatal error: Call to a member function insert() on a non-object in C:\wamp\www\teste\wp-content\themes\...
0
votes
0answers
222 views

How to add featured image on front end form?

I'm working on my first WordPress plug-in for front end posting where signed in users can post and manage their articles on front end. I'm pretty close to be done but can't find a way to add Featured ...
0
votes
0answers
197 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
122 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
0answers
33 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
259 views

wp_insert_post questions

I'm trying to add posts using wp_insert_post, but a few issues occur. First the code: function importposts() { $fh_import = @fopen( dirname( __FILE__ ) . '/importposts.txt', 'r' ); if ( $...
0
votes
0answers
504 views

wp_insert_post hook not being called with wp_publish_post or wp_insert_post?

I have a plugin that converts hashtags (any text that starts with #) into Wordpress tags. It's working great when I manually create a post via the Wordpress dashboard, but doesn't work when I ...
0
votes
0answers
246 views

Automatically add another subpost of the same parent when a subpost is saved

I figured it out how to add one subpost when a post is saved. But now I need to know how I can get another subpost of the same parent when a subpost is saved. Could anybody help me out? This is what ...
0
votes
0answers
326 views

Update fields with post object and custom tax with wp_insert_post

Updated Post 'update_field' Function is Acf Plugin $supplier_one = 'my supplier'; $supplier_two = 'my supplier TWO'; $post_id_one = 555; $post_id_two = 556; update_field('suppliers', $supplier_one, $...
0
votes
0answers
889 views

Getting error when using wp_insert_post()

When I use wp_insert_post() I get a white page that says "Are you sure you want to do this?". I get no PHP errors. I am using this outside of wordpress and have wp-load.php as well as /wp-admin/...
0
votes
0answers
66 views

Omitted Content After Post-Publish Insertion

I have a string that contains $thehtml but whenever I insert it manually into a custom post it appears that wordpress alters/strips down the html.... I've already tested/outputted $thehtml string in a ...
-1
votes
0answers
20 views

How to know find the input id for use it on wp_insert_post

I made wp plugin for automatic posting require 'crawel.php'; if (isset($_POST['activated']) && is_admin()){ $new_page_title = $manga_name; $...