Get custom Category from a custom post type

Asked

Viewed 459 times

0

I created a custom post type, and a taxonomy with the CTP UI plugin, but when it comes to listing in the loop the categories that are marked in the posts are not listed.

<?php
    $args = array(
        'post_type' => 'oferta',
        'orderby'   => 'menu_order',
        'order'     => 'ASC',
        'posts_per_page' => -1
    );  

    $loop = new WP_Query($args);

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

        echo "<pre>";
        var_dump(get_the_category($post->ID));
        echo "</pre>";
?>

<?php endwhile; ?>

My return:

inserir a descrição da imagem aqui

  • I managed to solve this problem:

  • I was able to solve this problem: $categoria = get_the_terms($post->ID, 'ofertas_categoria');&#xA;var_dump($categoria[0]->name);

1 answer

1

Hello. I managed to do using this formula

 <?php
    $taxonomia = "sua taxonomia";
    $terms = get_terms($taxonomy, array(
        "orderby"    => "count",
        "hide_empty" => false,
        ));

    foreach($terms as $term) {
    // faça alguma coisa
    }

or can adapt to as long as you have wordpress post.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.