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

103 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3
votes
1answer
173 views

Add PHP block template to content using wp_insert_post

I have created a block template so that every new post starts with a certain collection of blocks. In the below reduced example, let's say that the block template contains just a heading block and a ...
3
votes
1answer
512 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
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 ...
2
votes
1answer
208 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
0answers
1k 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 ...
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
32 views

How to use wordpress $polylang->model->set_post_language in custom php code?

I am creating a custom content engine that posts artwork content (uploading images from dropbox, building the content from data in an Excel spreadsheet, using a custom table for content management etc....
1
vote
0answers
110 views

Auto-Select Parent Category as Primary

I am using Yoast SEO Premium to handle the selection of Primary Categories. I am currently working with a Listing (listing) custom post type with a hierarchal taxonomy of Listing Category (listing_cat)...
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 ...
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
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 ...
1
vote
0answers
167 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
177 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
142 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
582 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
2answers
489 views

wp_insert_post via shell category not being inserted

I'm using this code: $post = array( 'post_content' => $desc, 'post_title' => $name_new, 'post_status' => 'publish', 'post_type' => 'portfolio_page', ...
1
vote
1answer
224 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
205 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 ...
0
votes
0answers
9 views

How to set template type on post created with a particular taxonomy?

I have a plugin that automatically converts Contact Forms to Post. I made sure that all the posts submitted by this plugin contain a particular taxonomy. Category: "Discussion nuggets". I ...
0
votes
0answers
13 views

wp_set_object_terms() custom taxonomy not working correctly when using insert post

I'm using wp_set_object_terms($postId, Array('tag1','tag2','tag3'), 'customtaxonomy'); with wp_insert_post to automatically create a new post. it will show as But on wordpress editor it is separated ...
0
votes
0answers
26 views

How to trigger a function when submit a form

How can I make work these functions not just when the user profile is updated. Also when a frontend form is submited? Here the functions: function get_channel_by_author( $user_id ) : int { // if we ...
0
votes
1answer
12 views

What is the correct way that when creating a custom post type assign values to custom fields created with pods framework?

I am trying to create a custom post type input using the wp_insert_post function, this custom post type called game was created using the pods framework and contains a series of custom fields which I ...
0
votes
1answer
34 views

WordPress PHP custom function is causing 500 Internal Server Error Connection Timeout

I wrote a custom script to insert a post into WordPress and upload 3 images to the WP uploads directory. To write the post I use the WP function wp_insert_post( $wp_post_array, true );. Inside the ...
0
votes
0answers
11 views

No ACF post meta when using get_post_custom during save_post

When I save/publish a page, I want it to save to all blogs in multisite including its custom fields (using Advance custom fields). The problem is that, when I tried to look at the value of post_meta ...
0
votes
0answers
16 views

Cannot insert HTML content even removing kses filters

I am creating post using the following code, but I cannot make the HTML content go through, they are being stripped automatically.. $post_data = [ "post_title" => $question, "post_content" =&...
0
votes
1answer
19 views

How do I find out which (page) template file my custom child post is looking for?

I am trying to make something like a web-app with WP. One of the issues I'm facing now is that I cannot find out which page template file my post is looking for. I have looked at template file ...
0
votes
1answer
19 views

Sanitize WordPress Array Input?

I have a form that submits the data in array format. I have sanitized all the data and also tried to escape it using esc_attr, but it is a function of escaping and not sanitizing. Is there a better ...
0
votes
0answers
14 views

Wordpress New Post via ajax call

I have added this field to the Add New Post page And i get data via ajax into console, I want to update post title and content when i click button "Import Data". jQuery(document).ready(...
0
votes
0answers
28 views

wp_insert_post() Add and specific ID to the body of that

Is there a way to add an specific ID to the body of that post that it's created by that method? The thing is, I'm creating a new post using this $new_page = array( 'post_type' => ...
0
votes
0answers
108 views

Random post_id at wp_insert_post

How I can use an absolute random post_id in wp-admin at wp_insert_post? I need stored in wp-admin a unique random post_id, but not I have only: 2210, 2212, 2214. As I understand it, this will not work ...
0
votes
1answer
104 views

wp_insert_post($post), add an array of values with update_post_meta

i try to store an array in multiple custom fields via post creation (wp_insert_post). The array is $event_test and the key is event_test on the meta_input. On form submit, the custom field is shown, ...
0
votes
2answers
122 views

How to prevent wp_insert_post from creating a new post every second?

I am trying to create a simple plugin that creates only one new post. The code I have written creates a the same new post every second. Below is the code I have. What would need to be added so it ...
0
votes
0answers
41 views

Programmatically Upload Image to Media & CDN

I'm trying to create a feature that allows my website to: Crawl through a CSV file and programmatically create a post Upload a featured image based off a URL from the CSV file to the Media Library (...
0
votes
0answers
45 views

WC attributes and terms cannot be added with the first pass of the script

In general, I am trying to insert/update post of type 'product' with attributes and terms into tax_input. It does not happen as expected. Firstly I tried to use wp_insert_post with 'tax_input' key ...
0
votes
0answers
52 views

Updating failed message when a wp_insert_post function is hooked to save_post hook

I was creating a function which creates a new custom post type with the category or taxonomy name if it was created from the post editor. I am simply using the wp_insert_post function with the ...
0
votes
1answer
325 views

how to create a category with wp_insert_post and post_category

I am trying to create a post with php and its wordpress functions. I am using wp_insert_post () but I can not assign a custom category type text to the post nor create it I have this code: ...
0
votes
1answer
35 views

Creating categories while importing via CSV

I have a CSV that I am importing via a custom plugin I made. This will create a CPT that has a few ACF fields. This CPT is called Formula, and it has a taxonomy associated with it called formula_type. ...
0
votes
0answers
82 views

wp_inset_post not adding taxonomy (using wp_set_object_terms)

The following runs through a cron job and successfully creates and publishes the post to a custom category. However, it does not attach a custom taxonomy (ap_job_status) term (ID 3) to the post. $...
0
votes
0answers
102 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
1answer
255 views

Meta inserted through wp_insert_post gets messed up

I'm extending the Woocommerce Product CSV Import functionality to import more data. I'm inserting a CPT with 2 metadata, a string (URL) and a bool, and the post_meta inserted gets messed up. It ...
0
votes
1answer
322 views

tax_input in wp_insert_post partly not working

I'm inserting a post via wp_insert_post() and in the $args the tax_input looks like this: 'tax_input' => array( "programmas" => 'Modern Family', "zenders" => 'ABC', ), But what is ...
0
votes
1answer
103 views

wp_set_post_terms() seems very slow

Is it normal for wp_set_post_terms() to be very slow? When wp_insert_post() it takes about 1 second. Adding 4 wp_set_post_terms() 7 - 10 seconds to the operation. Pseudo code example: $values = ['...
0
votes
0answers
29 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
1answer
540 views

wp_insert_post not inserting post

I'm trying to insert a post when a user (aka me) clicks on the button (this button is inside a meta box on the admin dashboard). This doesn't happen and I don't know why. When I put the content of my ...
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' ); ...
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
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
177 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 ...