By passing the _builtin
argument to get_post_types()
, only WordPress default post types will be returned.
Instead, just pass public
as an arguement,
Here’s an example of output on a development site with WooCommerce activated:
var_dump(get_post_types(['public' => true]));
//result
array(4) {
["post"]=>
string(4) "post"
["page"]=>
string(4) "page"
["attachment"]=>
string(10) "attachment"
["product"]=>
string(7) "product"
}
With no arguments (non-public post types are returned along with public):
var_dump(get_post_types());
//result
array(11) {
["post"]=>
string(4) "post"
["page"]=>
string(4) "page"
["attachment"]=>
string(10) "attachment"
["revision"]=>
string(8) "revision"
["nav_menu_item"]=>
string(13) "nav_menu_item"
["product"]=>
string(7) "product"
["product_variation"]=>
string(17) "product_variation"
["shop_order"]=>
string(10) "shop_order"
["shop_order_refund"]=>
string(17) "shop_order_refund"
["shop_coupon"]=>
string(11) "shop_coupon"
["shop_webhook"]=>
string(12) "shop_webhook"
}