$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How to display custom post type tags?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to display custom post type tags?

matteradmin8PV0评论

I have created custom post type with 'members'

 <?php
$member = new CPT(array(
    'post_type_name' => 'members',
    'singular' => __('Members', 'c2s'),
    'plural' => __('Members', 'c2s'),
    'slug' => 'Members'
),
   array(
    'supports' => array('title', 'editor', 'thumbnail', 'comments'),
    'menu_icon' => 'dashicons-groups'
));

$member->register_taxonomy(array(
    'taxonomy_name' => 'members_tags',
    'singular' => __('Members Tag', 'c2s'),
    'plural' => __('Members Tags', 'c2s'),
    'slug' => 'member-tag'
));

?>

I am trying to print/display members_tags into the individual post.

I have created custom post type with 'members'

 <?php
$member = new CPT(array(
    'post_type_name' => 'members',
    'singular' => __('Members', 'c2s'),
    'plural' => __('Members', 'c2s'),
    'slug' => 'Members'
),
   array(
    'supports' => array('title', 'editor', 'thumbnail', 'comments'),
    'menu_icon' => 'dashicons-groups'
));

$member->register_taxonomy(array(
    'taxonomy_name' => 'members_tags',
    'singular' => __('Members Tag', 'c2s'),
    'plural' => __('Members Tags', 'c2s'),
    'slug' => 'member-tag'
));

?>

I am trying to print/display members_tags into the individual post.

Share Improve this question asked Aug 3, 2017 at 6:24 Rabin RaiRabin Rai 11 silver badge2 bronze badges 1
  • Possibly using the WP Custom Post Type Class which is now PostTypes by Joe Grainger – admcfajn Commented Nov 9, 2018 at 7:09
Add a comment  | 

1 Answer 1

Reset to default 2

You can use get_the_term_list() to output a list of links:

<?php echo get_the_term_list( get_the_ID(), 'members_tags', '', ',' ); ?>

That will output a comma-separated list of links to attached member_tags.

If you want the raw tags so you have more control over HTML, use get_the_terms()

<?php $member_tags = get_the_terms( get_the_ID(), 'members_tags' ); ?>

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far