倚天杖
我已经通过以下方式做到了这一点$is_post_exists = post_exists($post->title);if ($is_post_exists === 0) { $post_id = wp_insert_post(array( 'post_title' => $post->title, 'post_date' => $post->date, 'post_content' => $post->excerpt, 'post_author' => 1, 'post_status' => 'publish', 'meta_input' => array( 'fifu_image_url' => $post->image, 'fifu_image_alt' => $post->title, '_cmb_link' => $post->link, ) )); $termObj = get_term_by('name', $post->newspaper->title, 'newspaper'); set_post_format($post_id, $post->type); if ($termObj) { wp_set_object_terms($post_id, array($termObj->term_id), 'newspaper'); } else { $new_newspaper = wp_insert_term($post->newspaper->title, 'newspaper'); wp_set_object_terms($post_id, array($new_newspaper['term_id']), 'newspaper'); } if ($post_id) { $added_posts[] = $post_id; }} else { $not_added_posts[] = $post->id;}