0

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

1

1 Answer 1

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

);
1
  • thats not working :( Jun 5, 2020 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.