我有一个自定义的帖子类型- "data-result“,其中有5个已发布的帖子。
我还有另一个帖子类型"data-collection-tool“,当用户访问/编辑”data-collection-tool“帖子时,它会从前端创建一个"data-result”帖子,效果很好。
我想在仪表板上显示一个通知,当管理员试图编辑“数据收集工具”帖子,但有一个或多个“数据结果”帖子。
代码
function ws48356743_warn_questionnaire_editor() {
if(get_post_type() == 'data-collection-tool' ){
?>
<div class="notice notice-warning is-dismissible">
<p><?php _e( 'Done! '.wp_98435409_checkResultsExist(get_the_ID()), 'sample-text-domain' ); ?></p>
</div>
<?php
}
}
add_action( 'admin_notices', 'ws48356743_warn_questionnaire_editor',1,0 );为此,我在一个单独的函数中查询"data-result“:
function wp_98435409_checkResultsExist(){
$args_n = array(
'post_type ' => 'data-result',
'post_status' => 'publish',
'posts_per_page' => 9999
);
$p = get_posts($args_n);
print_r($p);
wp_reset_postdata();
}get_posts返回一个空数组,我不知道为什么。
上面的所有代码都在functions.php中运行
有谁有什么建议吗?
谢谢
发布于 2017-03-21 23:52:14
一个流氓空间停止了这项工作
$args_n = array(
'post_type' => 'data-result', // <- was here in 'post_type '
'post_status' => 'publish',
'posts_per_page' => 9999
);https://stackoverflow.com/questions/42925550
复制相似问题