Change labels of custom post type via child theme

$wp_post_types is a global array that holds post_type objects, which in turn have a labels property. You can change $wp_post_types[$post_type]->labels after the parent theme has set the CPT. Add higher priority to init hook. Add the following code in your theme’s functions.php file. For more information, check out the codex article on get_post_type_object. function change_post_object_label() … Read more

Custom Post Type .current-menu-item not applying on Custom Post Type Archive Page

I found an answer by searching in similar posts and links. I added a line to fit my needs (I wanted to prevent my blog page to get highlited when on a custom post).See this line: unset($classes[array_search(‘current_page_parent’,$classes)]); Solution function add_parent_url_menu_class( $classes = array(), $item = false ) { // Get current URL $current_url = current_url(); … Read more

Custom post type within a subdirectory

When you register your post type, add the subdirectory to the has_archive argument, and as the slug argument of the rewrite argument: $args = array( // … other args removed for clarity ‘rewrite’ => array( ‘slug’ => ‘subdirectory/custom-post-type’ ), ‘has_archive’ => ‘subdirectory/custom-post-type’, // … ); register_post_type( ‘your_cpt’, $args );

How to filter by custom post type in taxonomy archive pages

That is the normal behaviour. If you go the archive of one taxonomy term you will get all posts, of any type, with this taxonomy term. One solution can be, for example, adding ?custom_type=files or ?custom_type=questions to your URLs and alter the main query in the pre_get_posts filter: add_action( ‘pre_get_posts’, ‘my_pre_get_post’ ); function my_pre_get_post($query){ if(!empty($_GET[‘custom_type’])){ … Read more

automatically save custom post type title as a category

Hook into save_post, and check if the category already exists (to avoid double creation on post edit). If category doesn’t exist create it using wp_insert_term and assign to post using wp_set_object_terms add_action(‘save_post’, ‘add_title_as_category’); function add_title_as_category( $postid ) { if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ) return; $post = get_post($postid); if ( $post->post_type == ‘post’) { // … Read more