0

Can anyone help me here. I want to list all the custom posts with the type 'portfolio' in this loop, where they have the 'Project Categories' set to 'ABC'. The below doesn't work, I think the issue is that the '' array parameter is looking at the main WP 'Categories'. Can someone help me to get it working please? Cheers.

$loop = new WP_Query(
    array(
        'post_type'      => 'portfolio',
        'posts_per_page' => 50,
        'category_name'  => 'ABC',
    )
);

while ( $loop->have_posts() ) :
    $loop->the_post();
    ?>

    <div class="half-column">
        <h2><?php the_title(); ?></h2>
    </div>

<?php endwhile;
wp_reset_postdata();

2 Answers 2

1

Is that category or custom taxonomy?

if this is a category, then try this one.

<?php
$loop = new WP_Query(
array(
    'post_type' => 'portfolio',
    'posts_per_page' => 50,
    'category__in' => array('8','9','10'), // your category ids
)
);
while ( $loop->have_posts() ) : $loop->the_post();

?>

<div class="half-column">
<h2><?php the_title(); ?></h2>
</div>

<?php endwhile;
wp_reset_postdata();
?>

Or if this custom taxonomy, try this one

<?php
$loop = new WP_Query(
array(
    'post_type' => 'portfolio',
    'posts_per_page' => 50,
    'tax_query' => array(
        array (
            'taxonomy' => 'yourTaxonomy',
            'field' => 'slug', //type, id or slug
            'terms' => 'yourTermSlug',
        )
    ),
)
);
while ( $loop->have_posts() ) : $loop->the_post();

?>

<div class="half-column">
<h2><?php the_title(); ?></h2>
</div>

<?php endwhile;
wp_reset_postdata();
?>

let me know the update. Thank You

2
  • 'project-type' => 'ABC' worked for me in the end.
    – dubbs
    Jun 23 at 22:16
  • Okay, If this is work for you, please mark this as solved. Thank You. Jun 23 at 22:17
0

This solution worked for me 'project-type' => 'ABC'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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