0
カスタムポストタイプがマルチサイト設定でしたarticle
は、カスタムフィールドによってネットワーク上の他のポストとの関係を持っていますalphanumeric_id
このキーは各ブログで一意であり、関連する投稿が生成されますプログラムで私がアーカイブしたいどのようadd_action('wp_insert_post', 'bZive_create_TranslatedContent', 15, 3);
ゴミ箱でマルチサイトのカスタムフィールド値によってポストされた
function bZive_trash_TranslatedContent($post_id){
// Get the current blog id
$original_site_id = get_current_blog_id();
$postTypes = array('profile', 'article');
$postType = get_post_type(get_the_ID());
$randomString = get_post_meta(get_the_ID(), 'alphanumeric_id', true);
$args = array(
'public' => true,
'limit' => 500
);
$sites = wp_get_sites($args);
$tests = array();
foreach ($sites as $site) {
switch_to_blog($site['blog_id']);
if(get_current_blog_id() != $original_site_id and get_current_blog_id() != 1){
$args = array(
'post_type' => 'article',
'post_status' => array(
'publish', 'draft', 'pending','auto-draft', 'future', 'private'
),
'meta_query' => array(
array(
'key' => 'alphanumeric_id',
'value' => $randomString ,
'compare' => '=',
),
),
);
$posts = new WP_Query($args);
if($posts->have_posts()) {
while($posts->have_posts()) {
$posts->the_post();
// Move the post to trash
wp_trash_post(get_the_ID());
}
}
wp_reset_postdata();
}
restore_current_blog();
}
}
add_action('trash_post','bZive_trash_TranslatedContent',10,3);
に:私はゴミ箱に1つのポストを移動した場合 - すべての関連する投稿はあまりにもゴミ箱に移動する必要があります。しかし、何とか投稿が削除されていない - WP_Queryをテストしたところ、正しい投稿が得られましたが、削除されません。