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 );
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742401542a4437009.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