[wp-trac] [WordPress Trac] #43362: wp-cron duplicate wp_insert_post
WordPress Trac
noreply at wordpress.org
Tue Feb 20 02:56:09 UTC 2018
#43362: wp-cron duplicate wp_insert_post
----------------------------+-----------------------------
Reporter: jblara25 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Cron API | Version: 4.9.4
Severity: normal | Keywords:
Focuses: administration |
----------------------------+-----------------------------
When trigger wp-cron to run. I found out that every post title with the
tag < and > will be duplicate more. But if I will run it in the plugin
itself, It`s not duplicating.
Any solution for this really appreciated. Thank you.
Here`s the function below :
{{{#!php
<?php
function process_movie($movie){
$already_insert = false;
//check if movie already exist
$movie_post =
get_page_by_title($movie['MovieTitle'],OBJECT,'movieinfo');
$movie_status = get_post_status($movie_post->ID);
if($movie_post->post_title == $movie['MovieTitle']){
$already_insert = true;
$movie_post_id = $movie_post->ID;
}
if( get_page_by_title($movie['MovieTitle'],OBJECT,'movieinfo') &&
$movie_status != 'trash'){
$movie_post_id = $movie_post->ID;
}
else{
$movie_post_id = $this->save_movie($movie);
}
return $movie_post_id;
}
function save_movie($movie){
$postarr = array(
"post_title" => $movie['MovieTitle'],
'post_type' => 'movieinfo',
'post_status'=> 'publish'
);
$movie_post_id = wp_insert_post($postarr);
foreach ($movie as $field_name => $value) {
if(empty($value)){
$value = '';
}
$field_key =
array_search($field_name,$this->movieinfo_field_keys);
update_field($field_key, $value, $movie_post_id);
}
unset($field_name);
unset($value);
return $movie_post_id;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43362>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list