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
  • 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
Add a comment  | 

1 Answer 1

Reset to default 0

Update 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