Skip to main content

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
0 answers
15 views

How to add a post page from a button without reloading

I am a novice in developpement and I am trying to create a page. When I click on the button Gutemberg, it will generate a post page with a text and an image. The problem is that the page is created ...
OceaneEMILE's user avatar
0 votes
0 answers
21 views

wp_insert_post() function doesn't create posts after I deleted the first created Post by this function

I have wroted a function and hooked it to set_user_role action hook. here is my snippet: add_action( 'set_user_role', 'createTeacherPage', 10, 3); function createTeacherPage($user_id, $...
ata ashrafi's user avatar
0 votes
0 answers
31 views

Set Variant options/attributes values on WooCommerce

I can insert variant options/attributes with no default values(variant name) in order to display following Variant options area with selected attribute names(Renk,Beden) on the product, by using ...
blueway's user avatar
  • 23
1 vote
1 answer
22 views

Add a post when another post type is inserting

I want to add a product when service post type inserting or updating. Below is the code. It works but it keep generates products while the code executing. What is the wrong with this code? add_action( ...
Avijit Palit's user avatar
1 vote
1 answer
46 views

OpenAI api for creating wordpress posts - wp_insert_post create post three times instead of once

I have a custom PHP script which should get response from OpenAI API and build HTML article content from it and then push it to WP through wp_insert_post() function. When I do echo for the article it ...
Martin Orešanský's user avatar
0 votes
1 answer
56 views

wp_insert_post inserts 3 posts at once?

I want to write an import of events (that I had as a text). The post are inserted, but each post is inserted 3 times!? I'm running a function on after_setup_theme in my functions.php. What I do: I ...
beat's user avatar
  • 43
0 votes
0 answers
20 views

Best approach for importing numerous posts from API data?

I am attempting to creating a number of new posts on my site through data provided by an API. All in, there would be around 75,000+ new posts. I had previously hooked into the init action and set the ...
zeropsi's user avatar
  • 101
0 votes
2 answers
125 views

large number (bigint) for post ID issue in database

the ID of my latest post is 796978707878960002. I manually created it using the code below: wp_insert_post(array( 'import_id' => 796978707878960002, 'post_title' => '-test' )); Now, ...
mhdi's user avatar
  • 1
0 votes
1 answer
142 views

Getting author's nickname as meta value

This is code I set on function.php I made it to have original author's nickname as custom value. function data_nickname( $post_id, $post, $update ) { $data_nickname = get_post_meta($post->ID, '...
cwhiro's user avatar
  • 25
0 votes
1 answer
72 views

Admin notice on wp_insert_post

I am trying to display some error messages in case some conditions are not met when using wp_insert_post. However, it the admin_notice doesn't seem to trigger. Here's the example I have: ...
dvm node's user avatar
0 votes
1 answer
134 views

Can't send form data to wpdb when URL has query string

I have a table called wp_invites which contains a list of invitees. This table contains a column called reference, which is added to the URL as a query param in order to customise their invite (i.e. ...
Freddy's user avatar
  • 147
1 vote
1 answer
577 views

Create Page with Template File from Plugin Folder

I have a plugin that creates a template file stored in the plugin's 'templates' folder. It also creates a new page using code similar to: $template_file = plugin_dir_path( __FILE__ ) . '/...
Rick Hellewell's user avatar
1 vote
0 answers
389 views

Updating post object via ACF breaks front-end

I have set up a working WP Insert post, that loops through my API call. I am then updating my ACF post object field which is successful but... I am encountering an issue when I update my ACF post ...
EpicJacob's user avatar
1 vote
0 answers
15 views

Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week

Newbie to Wordpress and PHP! Every Monday, my task is to create one post (let's call it summary) in a custom post-type called "news". In summary, the "contents" field will be a ...
satoshi's user avatar
  • 11
0 votes
1 answer
192 views

Multipe array in meta_input

I want to insert post with wp_insert_post and add meta_input in it. I have to send my data with array but I have problem to send more than one Here is my code : wp_insert_post( array( ...
Mehran Pourjenabi's user avatar
0 votes
1 answer
81 views

Suitable hook when creating, updating and deleting posts programmatically

I am trying to create, update & delete posts programmatically from an API endpoint inside my plugin. My idea was to display these posts later on a dedicated page. Here's what I've written so far: ...
tearswep's user avatar
0 votes
0 answers
206 views

Insert Custom Field Value

I want to insert custom post type with it's custom fields values I have found this method to insert custom post type but with no custom fields wp_insert_post( array $postarr, bool $wp_error = false, ...
askuserahmed's user avatar
0 votes
1 answer
187 views

Creating posts with links from a txt file

I have a script which scrapes articles from the web and saves the url to a .txt file. I've created a custom plugin which on activation, loops through the urls and creates a draft post with the content ...
Robert Mifsud's user avatar
0 votes
0 answers
303 views

Import JSON feed into Wordpress Post (wp_insert_post) every 24 hours

I am importing a JSON feed using a php file I am then looping through the JSON data and creating/updating a post using the wp_insert_post function. I want to query the JSON feed every 24 hours to sync ...
Roger Flynn's user avatar
0 votes
1 answer
198 views

"transition_post_status" action creating two post with wp_insert_post

What I'm tiring, I've created a custom post-type called the recipe when creating a new post on the recipe, I have inserted a new post on another post-type it working fine but post created two times ...
Nayeem Farid's user avatar
0 votes
0 answers
138 views

Is it possible to pin a post in second position from top

as the topic says i wish to keep a post not on top but in second position so that new posts are on top while one of my choice will be just after the latest. Is that possible, can't find a plugin that ...
Nicola Risimini's user avatar
1 vote
1 answer
53 views

Pre insert data when adding new custom post fire a json error

here is what i have tried function mec_locations_cpt_add_content ( $data, $postarr) { //, $postarr if ( 'mec_locations_cpt' !== $postarr['post_type'] ) { return $data; } if ...
ari elbaz's user avatar
0 votes
0 answers
34 views

Why is my insert row only inserting the final row from the loop into the database rather than just inserting one

<?php session_start(); if(is_user_logged_in()) { global $wpdb; $id = get_current_user_id(); $recoveryID = null; // $results = $wpdb->get_results('SELECT * FROM ...
Sheran Malik's user avatar
0 votes
0 answers
127 views

Using wp_mail to send email?

I have certain instances where I want to send emails to both user and admin accordingly using wp_mail. The first instance is when a new user is created. The following code is used to create users: //...
Rohit kc's user avatar
0 votes
1 answer
213 views

How to run wp_insert_post() & wpdb on the background?

I have created a code to fetch data from a remote API then echo certain data & import those data into a post type using wp_insert_post() & post meta** using wpdb->query(). Here's my current ...
Amenadiel's user avatar
  • 125
0 votes
0 answers
121 views

How to show comments from different Plugins to same post type?

I have two different comments, but both are related to the same post type. The first comments in this way: <?php if (isset($_POST['submit_tickets'])){ $tickets_reply = $_POST['...
Rohit kc's user avatar
0 votes
1 answer
82 views

How to get custom post_author?

I have a post type that inserts email as a post. I also created users according to those emails. This is how I added my post type. $post_array = array( 'post_content' => $mail['...
Rohit kc's user avatar
0 votes
1 answer
206 views

How to check if `comment_meta` exists before inserting the comment?

I am inserting comments via wp_insert_comment and while doing so I am adding email replies only. Now, I want to check if the comment is already present or not before inserting and if does exist do not ...
Rohit kc's user avatar
0 votes
2 answers
218 views

How to get the `comment_post_ID`?

I have extracted the reply emails. The original emails are saved as CPT and work as Tickets in my plugin. I want the reply email to go as a comment to the original email. for($j = 1; $j <= $total; ...
Rohit kc's user avatar
0 votes
1 answer
1k views

How to let a user create a post by submitting a POST form?

So i have the following simple POST form in my home page: <form action="/wp-content/plugins/myplugin/my_create_post.php" method="POST"> <label for="title_given"...
PantelD's user avatar
  • 39
0 votes
1 answer
261 views

See if the email exists or not

I have extracted a bunch of emails using PHP IMAP connection and assigned those emails to a custom post type. Here's the code how I assigned those emails to custom post type. $total = $emails->...
Rohit kc's user avatar
0 votes
1 answer
1k views

Posts form with AJAX request - Plugin development

Trying to create a form with AJAX call on the Frontend where the users can submit a post. There is one text field, one textarea, and one file field. Here is the form: public function pp_html_template()...
upss1988's user avatar
0 votes
1 answer
560 views

wp_insert_post always returns 0 on one site, extensive testing done, can't get to the bottom

I have two sites. One, a fresh install, the other an existing site with errors/white screen of death on the wp-admin/post-new.php screen. I've disabled all of the active plugins, and enabled a default ...
Gary's user avatar
  • 63
0 votes
1 answer
187 views

wp_insert_post order problem

I’m sorry, I speak a little English. My code in my custom theme (functions.php) [only example]: $posts = array( '141th', // ... '3rd', '2nd', '1st' ); foreach( $posts as $post ) { wp_insert_post( ...
luckyluck31's user avatar
1 vote
1 answer
1k views

update post meta for checkbox in the admin when inserted in the front-end

Here's my problem, I allow a certain user type to create custom post type in the front-end of my site, with the wp_insert_post() function... users can put values within a form and there's couple of ...
T3mmX's user avatar
  • 23
0 votes
1 answer
625 views

Custom plugin foreach wp_insert_post not working

I'm sorry, I speak a little English. Why not works? My plugin: ~/wp-content/plugins/mypluggg/mypluggg.php <?php /** * Plugin Name: mypluggg */ function videos() { // file_get_content()...
jozs2021's user avatar
0 votes
0 answers
80 views

wp_insert_post not inserting post from XML

I'm using below to read XML file and import its content as a page in wordpress, but it's not working: add_action('import_demo', 'importIt'); function importIt(){ // The code until now $path = ...
Ajay Malik's user avatar
0 votes
1 answer
469 views

Call to undefined function wp_create_category()

I’m sorry, I speak a little English. My custom theme: ~/wp-content/themes/mycustomtheme/functions.php function mct_task() { include( get_template_directory() . '/inc/cron.php' ); } add_action( '...
jozs2021's user avatar
0 votes
1 answer
45 views

How can I pass php code as a content while publishing a post

I'm parsing JSON data and want to display it in a Wordpress post. Here's the code that I would like to publish. Any idea how I can include this in wp_insert_post. $url = "http://metaweather.com/...
Ravi.'s user avatar
  • 101
1 vote
1 answer
484 views

wp_insert_post if page doesn't exist under current page

I am trying to dynamically insert a page/multiple pages as a child under the current page in my template file, using wp_insert_post, however I need to first check if the page title already exists ...
Daryl Roberts's user avatar
0 votes
0 answers
266 views

wp_insert_post() crashing website

I have a website built with WordPress and I've been using the code snippets plugin in order to automate some backend stuff. I've been trying to create posts automatically but every time I run the ...
Qwello Lee's user avatar
0 votes
1 answer
60 views

Multiple array for post_content on plugin activation

sorry for my bad English. I want to create multiple pages when activating a plugin. This also works, but how do I get different content in the different pages? if (!current_user_can('activate_plugins')...
EndlessOne's user avatar
0 votes
2 answers
669 views

wp_insert_post from XML feed only inserting first post

My aim is to import all XML files from a folder inside the WordPress installation (/data/*.xml) To achieve this, I added action in functions.php: /** * Show 'insert posts' button on backend */ ...
Pbalazs89's user avatar
  • 115
0 votes
0 answers
79 views

XML FOLDER - wp_insert_post - how to assign XML variables to post

I'm trying to repurpose a code that worked for CSV files to do the same for XML-> That is import all files in the folder and create Wordpress custom posts(cikkek). So, I managed to parse the XML ...
Pbalazs89's user avatar
  • 115
-1 votes
1 answer
245 views

After wp_insert_post() custom post type does not show in the admin

I have an import script that uses wp_insert_post() to add events wordpress. The script works and is basically a foreach loop of array elements that calls the above function multiple times. My issue is ...
m33bo's user avatar
  • 101
1 vote
1 answer
176 views

Is wp_insert_post exactly the same as publishing a post through the core UI?

I'm building a plugin that will call the wp_insert_post() function. I need to know if it is functionally identical to posting via the UI. For example, would other plugins (I'm thinking particularly of ...
Matthew Brown aka Lord Matt's user avatar
0 votes
1 answer
1k views

Update post if exist from PHP

I want to publish post from php for automation reasons with dynamic data and cronjob. I have almost succeeded, you could say that it works, but in an incorrect way. If the title doesn't exist, create ...
JonatanPN's user avatar
1 vote
0 answers
412 views

how to upload a image from frontend with wp_insert_post and also update_post_meta?

I am using cmb2 for frontend form submission with custom post type name 'form'. But can not upload image with that. the first step is: array( 'name' => 'Image', 'type' =&...
Tajul Islam Saikat's user avatar
0 votes
0 answers
170 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 ...
Kenneth Gervacio's user avatar
0 votes
1 answer
336 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 ...
user615274's user avatar

1
2 3 4 5
9