自定义帖子类型存档错误,以最后一篇帖子为标题,无法工作

时间:2016-01-26 作者:Kevin Mamaqi

我有一个叫cpt的Videos 这突然不起作用了。在存档页面中,仅显示最后一个视频。存档标题不再是视频,而是存档,而浏览器标题是最后一个(添加的)视频标题。(Here\'s the URL).

在同一个网站中,我有另一个用于Tours的CPT,它可以使用几乎相同的代码正常工作(here).

我用的是archive-video.php 具有以下代码的模板文件:

<?php
get_header(); ?>

<div class="container">
  <div class="row">
    <div class="col-sm-12">

      <?php if ( have_posts() ) : ?>

      <header class="seccion">
        <?php the_archive_title( \'<h1 class="page-title">\', \'</h1>\' ); ?>
        <?php 
          if ( ICL_LANGUAGE_CODE==\'en\' ) { 
            echo do_shortcode(\'[searchandfilter fields="av,tipodevideo" types=",checkbox" submit_label="Go" class="post_filters" all_items_labels="All" empty_search_url="http://www.wildlionrecords.com/en/videos/"]\');
          }
          else {
            echo do_shortcode(\'[searchandfilter fields="av,tipodevideo" types=",checkbox" submit_label="Ir" class="post_filters" all_items_labels="Todos" empty_search_url="http://www.wildlionrecords.com/videos/"]\');
          }
        ?>
      </header><!-- .page-header -->
    </div>
  </div><!-- #row -->
</div><!-- #container -->

<div class="container">

  <?php 
    $startRow = true;
    $postCounter = 0;
  ?>

  <?php

    if (have_posts()) : while (have_posts()) : the_post();  
  ?>

  <?php
    if ($startRow) {
      echo \'<!-- START OF INTERNAL ROW --><div class="row">\';
      $startRow = false;
    }  
  ?>
<?php
$postCounter += 1; 
?>
<!-- This div serves as the template for each post returned within the loop -->
<div class="col-sm-4">
  <article class="post blog-post">
    <div class="video-container"><?php the_field(\'url_del_video\'); ?></div>
    <h3 class="titulo-video"><?php the_title(); ?></h3>
  </article>
</div>
<?php 

if ( 3 === $postCounter ) {
  echo \'</div><!-- END OF INTERNAL ROW -->\';
  $startRow = true;
  $postCounter = 0;
}
?>
<?php endwhile; ?>
<?php 
if ($postCounter !== 0 ) {
  echo \'</div><!-- END OF INTERNAL ROW -->\';
}
?>
<?php else:  ?>
  <div class="page-header"><h1>Uh Oh!</h1></div>
  <p>Sorry, for some reason the contents of this page isn\'t displaying.</p>
<?php endif; ?>

<?php wp_pagenavi(); ?>
</div><!-- END OF ROW -->
</div><!-- END OF CONTAINER -->


</div><!--/.container-->  

<?php else : ?>

  <?php get_template_part( \'template-parts/content\', \'none\' ); ?>

<?php endif; ?>

</div><!-- #container -->

<?php get_footer(); ?>
共有pre_get_posts 来自函数。php:

// ***************************
// ********   Pre get posts para videos

add_action( \'pre_get_posts\', \'custom_post_type_archive_videos\' );
function custom_post_type_archive_videos( $query ) {
    if( $query->is_main_query() && !is_admin() && is_post_type_archive( \'video\' ) ) {
        $query->set( \'suppress_filters\', true );
        $query->set( \'posts_per_page\', \'-1\' );
    }
}

add_action( \'pre_get_posts\', \'custom_post_type_tax_av\' );
function custom_post_type_tax_av( $query ) {
    if( $query->is_main_query() && !is_admin() && is_tax( \'av\' ) ) {
       $query->set( \'suppress_filters\', true );
       $query->set( \'posts_per_page\', \'-1\' );
    }
}


add_action( \'pre_get_posts\', \'custom_post_type_tax_tipodevideo\' );
function custom_post_type_tax_tipodevideo( $query ) {
    if( $query->is_main_query() && !is_admin() && is_tax( \'tipodevideo\' ) ) {
       $query->set( \'suppress_filters\', true );
       $query->set( \'posts_per_page\', \'-1\' );
    }
}

1 个回复
最合适的回答,由SO网友:Kevin Mamaqi 整理而成

这个问题与WordPress更新和permalinks有关,我只是更新了permalink结构(没有修改),一切都很好。

我不知道为什么,但如果你面临同样的问题或类似的事情,那么值得一试。

相关推荐