A
A
Alexander Sobolev2018-10-03 15:05:50
WordPress
Alexander Sobolev, 2018-10-03 15:05:50

How to get all taxonomies of a post?

Please tell me how to get all taxonomies of a post into an array of the form [taxonomy name]=>[id of the term to which the post is attached]
I try using wp_get_post_terms, but something went wrong ..

$taxonomies = array('estate_district', 'estate_type', 'estate_building_type', 'estate_operation', 'estate_class');
         foreach ($taxonomies as $tax) {
            $taxes_list = wp_get_post_terms($estate_id, $tax, array("fields" => "ids"));
            foreach($taxes_list as $tax_id => $id){ print $tax.' = '.$id; }

         }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Chesnokov, 2018-10-03
@cesnokov

It seems to me that it should be something like this:

foreach( $taxes_list as $tax_id => $id ){ print $tax_id . ' = ' . $id; }

A
Alexander Sobolev, 2018-10-03
@san_jorich

$taxonomies = array('estate_district', 'estate_type', 'estate_building_type', 'estate_operation', 'estate_class', 'estate_proprietor');
         foreach ($taxonomies as $taxonomy) { 
            $est_cat = wp_get_post_terms($estate_id, $taxonomy, array("fields" => "ids"));
            foreach ($est_cat as $cat => $cat_id) { $estate_object_data[$taxonomy] = $cat_id }
         }

In theory, I cycle through the list of taxonomies, take from each id of the term attached to the post and display the name of the taxonomy and the id of the term ... In theory, everything is simple .. but it does not display ..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question