有没有办法查询具有特定模板的Wordpress页面?这是我得到的,但没有显示任何东西:
<?php $my_query = new WP_Query(array( 'meta_key' => '_wp_page_template', 'meta_value' => 'template-city.php' )); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li>
<?php the_title(); ?>
</li>
<?php endwhile; ?>
Run Code Online (Sandbox Code Playgroud)
当然,还有名为的页面模板文件 template-city.php
jan*_*anw 21
如果post_type遗漏了WP将寻找帖子,你正在寻找页面.
<?php
$args = array(
'post_type' => 'page',//it is a Page right?
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => 'template-city.php', // template name as stored in the dB
)
)
);
$my_query = new WP_Query($args)
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10866 次 |
| 最近记录: |