How to Add Authors to Any WordPress Custom Post Type

WordPress developers use the “custom post type” feature for many different features, including some that are a million miles away from traditional “posts”.

For example, in WooCommerce, post types are used for Orders, Coupons, Products, and more.

Many of those post types are simplified versions of regular posts. They do not have Tags, Categories, Published Dates, Authors or other features.

We often have PublishPress users asking us how to add back some of these missing features. One of the most common requests is adding Authors.

It is possible to add back the Authors for almost any custom post type. I'm going to use the example of adding the Author to WooCommerce coupons, but you could do the same thing for many other post types.

  • Find the name of your custom post type. The easiest way to do that is to go to your WordPress admin area and look in the URL bar. You are looking for the name after post_type=. In the image below, the name is shop_coupon.

In the image below, the name is product.

  • Now you know the name of your custom post type, you can add the code below to your theme's functions.php file. Change shop_coupon to the name of your post type.
function add_author_support_to_posts() {
   add_post_type_support( 'shop_coupon', 'author' ); 
}
add_action( 'init', 'add_author_support_to_posts' );
  • Go to the WordPress admin area and check your result. In the image below, I have added Authors to WooCommerce coupons. Inside each coupon, I will now see an “Authors” box:

This technique is part of two other WooCommerce tutorials: Control Who Can Access WooCommerce Coupons and also How to Add Authors to WooCommerce Products.

5 Comments

  1. Thanks so much for this guys! Once you have added the support to show the Author in the back end, how do you display the Author name on the front end of the product?
    Thanks again!

Leave a Reply

Your email address will not be published. Required fields are marked *