1
私は別のCPTに1つのCPTを動的に追加します。wp_insert_post()を使用 - 複製を作成
function cpt_to_cpt(){
// Grab posts
$args = array(
'post_type' => ' custom_type1 ',
'order' => 'ASC',
'post_status' => 'publish',
'numberposts' => -1,
);
$posts = get_posts($args);
foreach ($posts as $post) {
wp_insert_post(array(
'post_type' => 'custom_type2',
'post_title' => $post->post_title,
'post_date' => $post->post_date,
'post_author' => $post->post->author,
'post_status' => 'publish',
)
);
}
add_action('init', 'cpt_to_cpt');
'add_action( 'wp'、 'cpt_to_cpt')'ありがとうございます。条件を使ってコードを修正しました: 'if(!get_page_by_title($ post-> post_title、OBJECT、 'custom_type2'))' –