Jak mohu získat taxonomie typu příspěvku?
Pokud mám typ příspěvku event
a musím zjistit seznam taxonomií, které jsou připojeny k tomuto typu příspěvku. Jak je najdu?
Hej kluci, myslím, že to mám! Po prohlédnutí několika funkcí v souboru taxonomie.php ve WordPressu jsem našel tuto funkci get_object_taxonomies();
, která udělala trik :)
Zde je funkce
function get_post_taxonomies($post) {
// Passing an object
// Why another var?? $output = 'objects'; // name / objects
$taxonomies = get_object_taxonomies($post, 'objects');
/*// Passing a string using get_post_type: return (string) post, page, custom...
$post_type = get_post_type($post);
$taxonomies = get_object_taxonomies($post_type, 'objects');*/
/*// In the loop with the ID
$theID = get_the_ID();
$post_type = get_post_type($theID);
$taxonomies = get_object_taxonomies($post_type, 'objects');*/
// You can also use the global $post
// edited to fix previous error $taxonomies
// edited to force type hinting array
return (array) $taxonomies; // returning array of taxonomies
}
get_categories bude dělat svou práci.
get_categories('taxonomy=taxonomy_name&type=custom_post_type');
Zkusil jsi něco? něco takového?
<?php
$args=array(
'object_type' => array('event')
);
$output = 'names'; // or objects
$operator = 'and'; // 'and' or 'or'
$taxonomies=get_taxonomies($args,$output,$operator);
if ($taxonomies) {
foreach ($taxonomies as $taxonomy ) {
echo '<p>'. $taxonomy. '</p>';
}
}
?>