我正在写一个插件,我需要显示有关帖子的管理员通知。我调用了提供消息的函数。
add_action('admin_notices', array($this, 'postNotices'));这是我的功能:
public function postNotices() {
$args = array(
'post_type' => 'demo_post_type',
'post_status' => 'publish',
'posts_per_page' => -1,
'ignore_sticky_posts' => 1
);
$query_post = new WP_Query($args);
if ($query_post->have_posts()) {
while ($query_post->have_posts()) {
$query_post->the_post();
// $my_meta = 'Im getting post meta here'; ?>
<div>Some notification</div>
<?php wp_reset_query();
}
}
}显示的通知工作正常,但是当我尝试创建一个新的帖子时,它会显示最后的帖子数据,比如在新的帖子页面中的帖子标题。这意味着wp_reset_query()函数没有使用admin_notices钩子,我认为。有什么建议吗?
任何建议都是非常感谢的。
发布于 2016-06-08 09:38:28
经过艰苦的研究,我找到了答案,开始了,
$args = array(
'post_type' => 'demo_post_type',
'post_status' => 'publish',
'posts_per_page' => -1,
'ignore_sticky_posts' => 1
);
$query_posts = get_posts($args);
foreach ($query_posts as $post) {
?>
<div>Some notification</div>
<?php
}不需要添加像wp_reset_query()这样的函数。找到答案但不知道逻辑是什么。如果有人知道,请在这里评论。
https://stackoverflow.com/questions/37695431
复制相似问题