How Do I Display Custom Post Type Value in WordPress?

When creating a custom post type in WordPress, you may want to display the value of the post type in the front-end of your WordPress site. There are a couple of ways to do this.

The easiest way is to use the post type’s taxonomy. You can add the following line to your theme’s functions.php file:

add_action(‘init’, ‘my_taxonomy_setup’); function my_taxonomy_setup() { register_post_type(‘custom-post-type’, array( ‘label’ => __( ‘Custom Post Type’, ‘mytheme’ ), ‘description’ => __( ‘A custom post type for displaying post type values’, ‘mytheme’ ), ‘public’ => true, ‘show_ui’ => true, ‘show_in_menu’ => true, ‘show_in_nav_menu’ => true, ‘menu_position’ => 5, ‘public_title’ => ‘Custom Post Type’, ‘rewrite_title’ => ‘Custom Post Type – Custom Title’, ‘supports’ => array( ‘title’ ), ‘taxonomy’ => ‘custom-post-type’, ‘custom_taxonomy’ => true, ‘hierarchical’ => false, ‘query_vars’ => array( ‘slug’ => ‘custom-post-type’ ), ‘tax_query’ => array( ‘slug’ => ‘custom-post-type’ ), ‘public’ => true, ‘show_in_menu’ => true, ‘show_in_nav_menu’ => true, ‘menu_position’ => 2, ‘depth’ => 1, ‘parent_id’ => ‘0’, ‘name’ => ‘Custom Post Type’, ‘description’ => ‘A custom post type to store post type values.’ ), ‘public’ => true, ‘show_in_menu’ => true, ‘show_in_nav_menu’ => true, ‘menu_position’ => 5, ‘depth’ => 1, ‘parent_id’ => ‘0’, ‘name’ => ‘Custom Post Type’, ‘description’ => ‘A custom post type to store post type values.’ ), ); }

In this example, the post type’s taxonomy is set to custom-post-type . You can then use the post type’s slug in the front-end of your WordPress site to display the post type’s value.

You can also use the post type’s custom taxonomy to display the post type’s value. In the example above, the post type’s custom taxonomy is set to true .

You can then use the post type’s custom_taxonomy slug in the front-end of your WordPress site to display the post type’s custom taxonomy.

Conclusion

There are a couple of ways to display custom post type values in the front-end of your WordPress site.