wordpress - 需要打印由我当前的分类页面过滤的帖子吗?
问题描述
我需要打印我当前分类页面过滤的所有帖子。我可以使用哪个查询来过滤当前页面分类的所有这些帖子?我正在尝试做一个动态小部件以用于更多具有不同类别的页面。我希望有一个人可以帮助我 。thx :) 我正在尝试使用此代码,但不起作用...
<?php
$args=array(
'post_type' => 'post,
'post_status' => 'publish',
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
解决方案
解决了:
<?php
$term_slug = get_query_var( 'term' );
$taxonomyName = get_query_var( 'taxonomy' );
$the_query = new WP_Query( array(
'post_type' => 'post',
'tax_query' => array(
array (
'taxonomy' => $taxonomyName,
'field' => 'slug',
'terms' => $term_slug,
)
),
));
?>
推荐阅读
- mongodb - 如何在.find()的mongo查询中迭代对象属性(动态)
- php - 调用未定义的方法 Illuminate\Support\Testing\Fakes\MailFake::assertQueued()
- amazon-web-services - 在生产环境中添加和更新新的 dynamo db 属性
- javascript - 如何使文本区域变得更高更宽以适应新文本
- android - Fileprovider 找不到配置的根错误
- postman - 如何将请求 JSON 存储在变量中并在模拟响应正文中使用它
- excel - 计算与先前金额的差额
- c++ - 检查 pthread 时出现 C++ 内部 CMake 错误
- android - View null 没有设置 NavController
- elasticsearch - TypeError:“IndicesClient”对象不可调用