Custom post type – list posts based on meta_key and display them divided by CPT taxonomy category

Here’s the code, rewriten from posts and categories to custom post types and taxonomy terms. Thanks to @PieterGoosen for providing the first version. http://pastebin.com/xKBepGQz <?php $args = array( ‘post_type’ => ‘produkty’, // your CTP name ‘meta_key’ => ‘produkt_nowosc’, // custom meta key for displaying, in my case: the newest product in offer ‘meta_value’ => ‘tak’, … Read more

Change Slug of a Custom Post Type

In the code you posted, the filter ctc_post_type_item_args gets applied to the $args array before it is passed into register_post_type(). Putting a function into your themes functions.php and hooking it to the filter should do the trick: function wpse_191003_ctc_post_type_item_args( $args ) { $args[‘rewrite’][‘slug’] = “your_new_slug”; return $args; } add_filter( ‘ctc_post_type_item_args’, ‘wpse_191003_ctc_post_type_item_args’ );

How to add current custom taxonomy slug to body class

You can follow similar approach with get_the_terms. Here is the function. function add_taxonomy_to_single( $classes ) { if ( is_single() ) { global $post; $my_terms = get_the_terms( $post->ID, ‘custom-taxonomy’ ); if ( $my_terms && ! is_wp_error( $my_terms ) ) { foreach ($my_terms as $term) { $classes[] = $term->slug; } } return $classes; } } add_filter( ‘body_class’, … Read more

How can I use archive-{post_type}.php theme template?

Custom post type archive page does not need “dumb” Page. In fact, there could be the culprit. You should try this: Remove /* Template Name: Staff */ from archive-staff_member.php (not needed) Remove “dumb” stuff Page (if created). There could be some permalink conflict. Go to Admin > Settings > Permalinks and re-save it (it will … Read more

Add custom CSS class to custom post type

Have a look at post_class(). Check if the theme using it (every good theme should). If so then you can use post_class filter to add appropriate classes to the container. Here is an example how you can use that filter add_filter(‘post_class’, function($classes){ if(!is_singular(‘song’)) return $classes; $additional_classes = array(‘song-entry’, ‘masonry-entry’, ‘col-‘, ‘loop-entry’, ‘col’, ‘clr’, ‘span_1_of_3’); $classes … Read more