wp query – I need to get all categories from a WP_Query

Question

Actualy i’m doing this

$loop = new WP_Query($args);

while ($loop->have_posts()) :
    $ID = $postData->ID;
    $freeCategories = get_terms(array(
        'taxonomy' => "product_cat",
        'fields' => 'names',
        'object_ids' => $ID
    ));

    foreach ($freeCategories as $cat) {
        if (!in_array($cat, $freeCategories)) {
            $catFiltered[] = $categoria; //here i save the categories
        }
    }
endwhile;

But, if for example i have 5 pages, i’ll only get the first page products categories.

I need the 5 products pages categories, Any idea?

Thanks.

0
Esteban García 2 months 2023-01-27T00:29:35-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse