Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.