admin管理员组文章数量:1336197
Im using the wordpress theme bridge and the portfolio with different categories. I edit the portfolio-loop to get a list of all items of the current category.
I found the following code here and tried to change it the way I need.
<?php
$args = array(
'post_type' => 'portfolio_page',
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
'portfolio_category' => get_query_var( 'portfolio_category' )
);
$my_query = new WP_Query( $args );
if ( $my_query->have_posts() ) {
echo '<ul>';
while ( $my_query->have_posts() ) {
$my_query->the_post();
echo '<li><a href="' . get_permalink( $post -> ID ) . '">' . get_the_title() . '</a></li>';
}
echo '</ul>';
}
wp_reset_postdata();
?>
But I get the complete of every portfolio from every category. The following part is not working.
'portfolio_category' => get_query_var( 'portfolio_category' )
It works, when Im adding a certain category like this:
'portfolio_category' => 'category-a'
Whats wrong? Thanks
Im using the wordpress theme bridge and the portfolio with different categories. I edit the portfolio-loop to get a list of all items of the current category.
I found the following code here and tried to change it the way I need.
<?php
$args = array(
'post_type' => 'portfolio_page',
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
'portfolio_category' => get_query_var( 'portfolio_category' )
);
$my_query = new WP_Query( $args );
if ( $my_query->have_posts() ) {
echo '<ul>';
while ( $my_query->have_posts() ) {
$my_query->the_post();
echo '<li><a href="' . get_permalink( $post -> ID ) . '">' . get_the_title() . '</a></li>';
}
echo '</ul>';
}
wp_reset_postdata();
?>
But I get the complete of every portfolio from every category. The following part is not working.
'portfolio_category' => get_query_var( 'portfolio_category' )
It works, when Im adding a certain category like this:
'portfolio_category' => 'category-a'
Whats wrong? Thanks
Share Improve this question edited May 25, 2020 at 10:26 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked May 25, 2020 at 10:01 Ingo LembkeIngo Lembke 1 1 |1 Answer
Reset to default 0Update your following part of code:
$term = get_queried_object(); $category_name = $term->slug; //category slug $args = array( 'post_type' => 'portfolio_page', 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', 'category_name' => $category_name );
本文标签: taxonomyList of all posts from current category on single portfolio page
版权声明:本文标题:taxonomy - List of all posts from current category on single portfolio page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742401526a2467981.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
portfolio_category
is not a native wp_query parameter. look at the category section of wp_query on how to correctly set this up – Bysander Commented May 27, 2020 at 11:23