Shoora
11/26/2018 - 1:42 AM

Filter a custom post type after it's been registered

Filter a custom post type after it's been registered

<?php

/**
 * Filter the Products CPT to register more options.
 *
 * @param $args       array    The original CPT args.
 * @param $post_type  string   The CPT slug.
 *
 * @return array
 */
function wds_client_filter_products_cpt( $args, $post_type ) {

	// If not Products CPT, bail.
	if ( 'products' !== $post_type ) {
		return $args;
	}

	// Add additional Products CPT options.
	$products_args = array(
		'has_archive' => true,
		'supports'    => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'page-attributes' ),
	);

	// Merge args together.
	return array_merge( $args, $product_args );
}
add_filter( 'register_post_type_args', 'wds_client_filter_products_cpt', 10, 2 );