我想在调用自定义帖子列表时使用页面slug作为分类法。
这项工作:
<?php $page_slug = basename(get_permalink()); ?>
<?php echo $page_slug; ?>
页面上显示“2017年12月”。
这也是:
<ul>
<?php
$args = array(
\'post_type\' => \'nomination\',
\'post_status\' => \'draft\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'month_category\',
\'field\' => \'slug\',
\'terms\' => \'december-2017\',
)
)
);
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<?php the_terms( $post ->ID, \'dealership_category\', \'\', \'\', \'\' ); ?><br>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br>
Submitted: <?php echo get_the_date( \'d/m/Y\' ); ?>
</li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<li>Nothing found.</li>
<?php endif; ?>
</ul>
那么为什么我不能让它工作:
<ul>
<?php $page_slug = basename(get_permalink()); ?>
<?php
$args = array(
\'post_type\' => \'nomination\',
\'post_status\' => \'draft\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'month_category\',
\'field\' => \'slug\',
\'terms\' => \'$page_slug\',
)
)
);
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<?php the_terms( $post ->ID, \'dealership_category\', \'\', \'\', \'\' ); ?><br>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br>
Submitted: <?php echo get_the_date( \'d/m/Y\' ); ?>
</li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<li>Test not working.3</li>
<?php endif; ?>
</ul>
页面上显示“测试不工作。3”。我不擅长PHP,所以我很困惑。