首页 > 解决方案 > 退出时不重置循环后数据(我怀疑)

问题描述

带有自定义元框的自定义帖子显示在 admin_notices 区域中。一切都正确呈现和样式,没有问题但是......添加新的常规帖子,类型页面的帖子或新的自定义帖子类型时;标题、内容和 slug 是预先填充的,而不是空白让我填写。如果我更改标题/内容,它会保存为新帖子。我已经删除了大块代码,只有当我删除以下函数时它才会消失。我什至从官方的WP_Query文档中重建它,但没有成功。

示例:图像在点击新页面后显示,它拉入标题/内容/slug 进行显示。如果我替换标题/内容,新页面将使用正确的内容和 slug 保存,它似乎被拉入显示。

保存后的新帖子

function dd_admin_notice_loop_display() {

  $dd_admin_all_query = new WP_Query(array('post_type'=>'dd-admin-notice', 'post_status'=>'publish', 'posts_per_page'=>-1));

  if ( $dd_admin_all_query->have_posts() ) : ?>
    <ul>
    <?php while ( $dd_admin_all_query->have_posts() ) : $dd_admin_all_query->the_post();
       $class = get_post_meta( get_the_ID() , 'ddadminalert', true ); ?>
         <li><?php echo '<div class="dd-notice notice ', print $class; ?> "><span class="dd-admin-title"><?php the_title(); ?></span><span class="dd-admin-content"><?php the_content(); ?></span></div></li>
    <?php endwhile; ?>
    </ul>
    <?php wp_reset_postdata(); 
    else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif;
}

add_action('admin_notices', 'dd_admin_notice_loop_display');

标签: phpwordpressfunction

解决方案


推荐阅读