Aleš Sýkora / November 28, 2023 / 0 comments
Display all custom fields meta and Taxonomies and terms of current post in WordPress
min read / Custom Code, WordPress / Share on: Twitter, LinkedIn, Facebook
Post summary: If you want to know everything about your current post, you will need to dump all custom fields and all asigned taxonomies and their terms. Display all post Meta’s This code will create list of custom fields assigned to the current post: Display all taxonomies and terms This code will create list like this:
If you want to know everything about your current post, you will need to dump all custom fields and all asigned taxonomies and their terms.
Display all post Meta’s
This code will create list of custom fields assigned to the current post:
<h3>All Post Meta</h3>
<?php
// Get all the data
$getPostCustom = get_post_custom();
foreach($getPostCustom as $name=>$value) {
echo "<strong>" . $name . "</strong>"." => ";
foreach ($value as $nameAr=>$valueAr) {
echo "<br />";
echo $nameAr." => ";
echo var_dump($valueAr);
}
echo "<br /><br />";
}
?>
Display all taxonomies and terms
This code will create list like this:
<h3>All Post Tax</h3>
<?php
function custom_taxonomies_terms_links() {
global $post, $post_id;
// get post by post id
$post = &get_post($post->ID);
// get post type by post
$post_type = $post->post_type;
// get post type taxonomies
$taxonomies = get_object_taxonomies($post_type);
$out = "<ul>";
foreach ($taxonomies as $taxonomy) {
$out .= "<li>".$taxonomy.": ";
// get the terms related to post
$terms = get_the_terms( $post->ID, $taxonomy );
if ( !empty( $terms ) ) {
foreach ( $terms as $term )
$out .= '<a href="' .get_term_link($term->slug, $taxonomy) .'">'.$term->name.'</a> ';
}
$out .= "</li>";
}
$out .= "</ul>";
return $out;
}
echo custom_taxonomies_terms_links();
?>
Fuel my passion for writing with a beer🍺
Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻