Skip to content

Instantly share code, notes, and snippets.

@gregrickaby
Created June 9, 2016 18:02
Show Gist options
  • Save gregrickaby/518090ce734dd98842adef6f82c597d0 to your computer and use it in GitHub Desktop.
Save gregrickaby/518090ce734dd98842adef6f82c597d0 to your computer and use it in GitHub Desktop.
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