没有,但你可以使用switch_to_blog()
函数切换到某个站点,然后使用常规WordPress函数检查该帖子类型上是否存在任何帖子。
例如
add_action(\'wp_loaded\', \'wpse167721_check_networkwide_events\');
function wpse167721_check_networkwide_events(){
global $wpdb;
$original_blog_id = get_current_blog_id(); // get the original blog id
// get network sites
$args = array(
\'network_id\' => $wpdb->siteid,
\'public\' => null,
\'archived\' => null,
\'mature\' => null,
\'spam\' => null,
\'deleted\' => null,
\'limit\' => 100,
\'offset\' => 0,
);
$sites = wp_get_sites($args);
foreach($sites as $site){
// switch to blog
switch_to_blog($site[\'blog_id\']);
if(!wpse167721_is_event_exists())
continue; // skip current iteration and go to the next one
// Event exists! do whatever you want to do
}
// lets switch to our original blog
switch_to_blog($original_blog_id);
}
function wpse167721_is_event_exists(){
$args = array(
\'post_type\' => \'event\', // change the cpt name here
\'posts_per_page\' => 1,
\'fields\' => \'ids\'
);
return count(get_posts($args));
}
Caution:此代码将在每次页面加载时为网络中的每个博客运行(因为它连接到
wp_loaded
). 如果您有一个大型网络,那么可以考虑批处理。
代码未测试