List of all posts from current category on single portfolio page

Question

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

0
Ingo Lembke 4 years 2020-05-25T05:10:32-05:00 0 Answers 76 views 0

Leave an answer

Browse
Browse