如何防止 wp_insert_post 重复发帖?
How to prevent duplicate posts with wp_insert_post?
如何防止在 single.php 上与 wp_insert_post
重复 post?
我的密码是
$post_id = wp_insert_post( array(
'post_status' => 'publish',
'post_type' => 'post',
'post_title' => 'Test Shop1',
'post_content' => 'Lorem ipsum'
) );
$post_type = 'shop';
$query = "UPDATE {$wpdb->prefix}posts SET post_type='".$post_type."' WHERE id='".$post_id."' LIMIT 1";
GLOBAL $wpdb;
$wpdb->query($query);
但是每次我刷新它都会添加重复项post..我该如何防止这种情况发生?请帮忙
$post_title = 'Test Shop1';
if (!post_exists($post_title)) { // Determine if a post exists based on title, content, and date
$post_id = wp_insert_post(array(
'post_status' => 'publish',
'post_type' => 'post',
'post_title' => $post_title,
'post_content' => 'Lorem ipsum'
));
}
如何防止在 single.php 上与 wp_insert_post
重复 post?
我的密码是
$post_id = wp_insert_post( array(
'post_status' => 'publish',
'post_type' => 'post',
'post_title' => 'Test Shop1',
'post_content' => 'Lorem ipsum'
) );
$post_type = 'shop';
$query = "UPDATE {$wpdb->prefix}posts SET post_type='".$post_type."' WHERE id='".$post_id."' LIMIT 1";
GLOBAL $wpdb;
$wpdb->query($query);
但是每次我刷新它都会添加重复项post..我该如何防止这种情况发生?请帮忙
$post_title = 'Test Shop1';
if (!post_exists($post_title)) { // Determine if a post exists based on title, content, and date
$post_id = wp_insert_post(array(
'post_status' => 'publish',
'post_type' => 'post',
'post_title' => $post_title,
'post_content' => 'Lorem ipsum'
));
}