Add one (not all) Custom Post Type to Archive
-
Using the lates version of WordPress, I would like to know how to get my Custom Post Type which has the “has_archive” set to true show up in the (weekly, monthly..) get_archives list without trowing a 404 or including all Custom Post Types?
I’ve searched and google the issue and got various recommendations but all seem to include all Custom Post Types to the date based Archives, where as I only need a specific Post Type to show when calling the wp_get_archives function.
So far I got all Custom Post Types to show up in the regular Archives with this code
add_filter( 'getarchives_where' , 'ucc_getarchives_where_filter' , 10 , 2 ); function ucc_getarchives_where_filter( $where , $r ) { $args = array( 'public' => true , '_builtin' => false ); $output = 'names'; $operator = 'and'; $post_types = get_post_types( $args , $output , $operator ); $post_types = array_merge( $post_types , array( 'post','referenzen' ) ); $post_types = "'" . implode( "' , '" , $post_types ) . "'"; return str_replace( "post_type = 'post'" , "post_type IN ( $post_types )" , $where ); } function my_get_posts( $query ) { if ( is_home() || is_category() || is_archive() && false == $query->query_vars['suppress_filters'] ) $query->set( 'post_type', array( 'post', 'referenzen', 'produkte' ) ); return $query; } add_filter( 'pre_get_posts', 'my_get_posts' );
But there must be a “hack” free solution to this as I can set each Custom Post Types “has_archive” parameter individually?
Any help is highly appreciated..
Regards, Marcel
- The topic ‘Add one (not all) Custom Post Type to Archive’ is closed to new replies.