I am creating a new template that will get all the custom post type (Case Studies) content, including the taxonomies values associated with it.
So far I got the following:
<section>
<h1><?php _e( 'posts', 'casestudies' ); ?></h1>
<?php get_template_part('loop'); ?>
<?php
$args = array('post_type' => 'casestudies', 'posts_per_page' => 3);
$query = new WP_Query($args);
while($query -> have_posts()) : $query -> the_post();
?>
<h2><?php the_title(); ?></h2>
<p>Meta: <?php the_meta(); ?></p>
<p>Excerpt: <?php the_excerpt(); ?></p>
<p>what_to_put_here_to_get_taxonomies_values????</p>
<?php endwhile; ?>
<?php get_template_part('pagination'); ?>
</section>
How do I get the taxonomy of it? I have tried multiple things but all seemed to fail and just getting more confused.
In WordPress, you can create (or “register”) a new taxonomy by using the register_taxonomy() function. Each taxonomy option is documented in detail in the WordPress Codex. After adding this to your theme's functions. php file, you should see a new taxonomy under the “Posts” menu in the admin sidebar.
A WordPress taxonomy is a way to organize groups of posts and custom post types. The word taxonomy comes from the biological classification method called Linnaean taxonomy. By default, WordPress comes with two taxonomies called categories and tags. You can use them to organize your blog posts.
assume: I register a taxonomy with custom post type name publication_category.
On your custom post type template write :
$terms = get_the_terms( $post->ID, 'publication_category' );
if ($terms) {
foreach($terms as $term) {
echo $term->name;
}
}
Just in case if it could help someone, I used "the_taxonomies()" function inside a loop of a custom post type.
<?php
while ( have_posts() ) : the_post();
$custom_post = get_post_meta( get_the_ID() );
//
?>
//html
//and stuff
<?php the_taxonomies(); ?>
<?php
endwhile;
?>
the result was:
Taxonomy-name: {Taxonomy-term}. <-- as a link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With