我有三个页面模板,主页、文档和公司,每个模板使用相同的CPT WP\\U查询代码,每个模板只更改了类别名称。主页运行良好,拉拽并显示我的CPT的正确类别。另外两个不起作用。
以下是主页的代码片段:
<?php
/*
Template Name: Homepage Reels
*/
/*
@package _tk
*/
get_header(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content">
<div class="container-fluid">
<?php $args = array( \'post_type\' => \'films\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'film-type\',
\'field\' => \'slug\',
\'terms\' => \'homepage\',
)
),
\'posts_per_page\' => \'-1\', );
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php /* Get the current post ID. */
$post_id = get_the_ID();
/* If we have a post ID, proceed. */
if ( !empty( $post_id ) ) { ?>
<div class="film_wrap col-md-4">
<?php // <h2 class="film_title"><?php the_title(); ?><?php //</h2> ?>
<?php $videourl = get_post_meta( $post_id, \'film_embed\', true );
if ( $videourl != \'\' ) {
echo wp_oembed_get( $videourl );
} ?>
<?php if ( get_post_meta( $post_id, \'film_textarea\', true ) ) : ?>
<div class="film_description">
<p><?php echo get_post_meta( $post_id, \'film_textarea\', true ); ?></p>
</div>
<?php endif; ?>
</div>
<?php } else { ?>
<p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php } ?>
<?php wp_link_pages( array(
\'before\' => \'<div class="page-links">\' . __( \'Pages:\', \'_tk\' ),
\'after\' => \'</div>\',
) ); ?>
<?php endwhile; ?>
<?php endif; ?>
以及文档模板:
<?php
/*
Template Name: Documentary Reels
*/
/*
@package _tk
*/
get_header(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content">
<div class="container-fluid">
<?php $args = array( \'post_type\' => \'films\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'film-type\',
\'field\' => \'slug\',
\'terms\' => \'documentary\',
)
),
\'posts_per_page\' => \'-1\', );
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php /* Get the current post ID. */
$post_id = get_the_ID();
/* If we have a post ID, proceed. */
if ( !empty( $post_id ) ) { ?>
<div class="film_wrap col-md-4">
<?php // <h2 class="film_title"><?php the_title(); ?><?php //</h2> ?>
<?php $videourl = get_post_meta( $post_id, \'film_embed\', true );
if ( $videourl != \'\' ) {
echo wp_oembed_get( $videourl );
} ?>
<?php if ( get_post_meta( $post_id, \'film_textarea\', true ) ) : ?>
<div class="film_description">
<p><?php echo get_post_meta( $post_id, \'film_textarea\', true ); ?></p>
</div>
<?php endif; ?>
</div>
<?php } else { ?>
<p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php } ?>
<?php wp_link_pages( array(
\'before\' => \'<div class="page-links">\' . __( \'Pages:\', \'_tk\' ),
\'after\' => \'</div>\',
) ); ?>
<?php endwhile; ?>
<?php endif; ?>
我通过WP\\U调试没有错误。测试地点如下:
http://thegallerymusic.com/test/想不到是什么让主页工作,但却导致文档/公司模板无法工作。有什么想法吗?