我想检查标题是否存在于wp_insert_post()
已触发。
然而,这种情况似乎并不像预期的那样起作用:
if( $wpdb->get_row("SELECT * FROM wp_posts WHERE post_title = \'" . trim($titles_arr[$i]) . "\' AND post_type=post", \'ARRAY_A\') ) {
// title do exist
// don\'t save
} else {
// ...perform save code
}
而且无论它是否存在,它总是可以保存。有趣的是,如果现有标题i my db是,例如:The best title in the world
和slugthe-best-title-in-the-world
举个例子trim($titles_arr[0])
(我正在通过foreach循环循环数组)数组,而不是调用该帖子中首先不应该保存的slugthe-best-title-in-the-world-2
如果我再次运行我的scirptthe-best-title-in-the-world-3
等