自定义 metabox 中的查询打破了“接管”对话框

问题描述 投票:0回答:0

我构建了一个 Wordpress 主题,它添加了“header”、“footer”和“underbar”作为自定义帖子类型,还向页面编辑器添加了一个自定义元框,带有下拉“选择”字段以选择要显示的页眉、页脚和下划线与此页面。 当然,为了填充这些下拉字段中可用的“选项”,我首先需要查询自定义页眉/页脚/下栏帖子,以使用有关现有页眉/页脚/下栏帖子的信息填充数组。

这是填充每个数组的代码块:

    // POPULATE HEADERS ARRAY //
    $args=array(
      'post_type' => 'header',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'ignore_sticky_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    $headers_array = array();
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post();
    global $post;
        $header_id = $post->ID;
        $header_title = get_the_title();
        $header_slug = $post->post_name;
        $headers_array[] = array('id' => $header_id, 'slug' => $header_slug, 'title' => $header_title);
    endwhile;
    }
    wp_reset_query();

    // POPULATE FOOTERS ARRAY //
    $args=array(
      'post_type' => 'footer',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'ignore_sticky_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    $footers_array = array();
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post();
    global $post;
        $footer_id = $post->ID;
        $footer_title = get_the_title();
        $footer_slug = $post->post_name;
        $footers_array[] = array('id' => $footer_id, 'slug' => $footer_slug, 'title' => $footer_title);
    endwhile;
    }
    wp_reset_query();

    // POPULATE UNDERBARS ARRAY //
    $args=array(
      'post_type' => 'underbar',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'ignore_sticky_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    $underbars_array = array();
    if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post();
        global $post;
            $underbar_id = $post->ID;
            $underbar_title = get_the_title();
            $underbar_slug = $post->post_name;
            $underbars_array[] = array('id' => $underbar_id, 'slug' => $underbar_slug, 'title' => $underbar_title);
        endwhile;
    }
    wp_reset_query();

现在,这一切都完美无缺,除了它在其他地方引起的一个意外故障。

如果有多个用户登录到站点的后端并且有人正在编辑页面并且我想接管该页面的编辑,当我点击页面进行编辑时我得到“已接管并且是目前正在编辑中。”对话框(如预期的那样),但是,我没有得到我应该得到的“返回”、“预览”和“接管”按钮,而是得到一个显示“Underbar”的按钮,单击该按钮时,需要我转到“下划线”页面,我在其中选择要编辑的下划线。或者如果没有 Underbar 帖子,按钮会显示“页脚”并将我带到“页脚”页面等。

我哪里错了?我认为“wp_reset_query()”可以避免这样的问题;我也试过“wp_reset_postdata();”就在“endwhile;”之后线,但仍然没有变化。

wordpress wordpress-theming custom-post-type meta-boxes page-editor
© www.soinside.com 2019 - 2024. All rights reserved.