Dev Dan
Dev Dan

Reputation: 1

get_category_ids() not working well on wordpress 6.0

Hi i have a very simple code which returns me the category_ID of a given product. In the latest version of wordpress 6.0, this function does not work -> get_category_ids (), returns an empty value and the link of the product contains a link "no-categories". In wordpress 5.9.1 everything works fine. Has anyone encountered such a problem? Please let me know, best regards, Daniel

Upvotes: 0

Views: 319

Answers (1)

Gruby
Gruby

Reputation: 11

I've got the same problem and couldn't find any direct solutions to this. I used workaround provided in this topic: https://stackoverflow.com/a/55575047/19547053 with wp_get_post_terms().

foreach ($order->get_items() as $item ) {
$term_names = wp_get_post_terms( $item->get_product_id(), 'product_cat', ['fields' => 'names'] );

// Output as a coma separated string
echo implode(', ', $term_names);}

Upvotes: 1

Related Questions