CPT Archive Question
-
Hi,
I used your excellent Custom Post Type UI plugin to easily create a custom post type. I also want my custom post types to show up in the tag archives along with my posts, so I inserted the following snippet into a custom plugin to create a tag archive that successfully merges my posts and custom post types:
<?php
/*
Plugin Name: Site-Specific WordPress Plugin
Description: Created per instructions found at https://docs.pluginize.com/article/17-post-types-in-category-tag-archives. The snippet below allows custom post types to appear in tag archives.
*/
/* Start Adding Functions Below this Line */function my_cptui_add_post_types_to_archives( $query ) {
// We do not want unintended consequences.
if ( is_admin() || ! $query->is_main_query() ) {
return;
}if ( is_category() || is_tag() && empty( $query->query_vars[‘suppress_filters’] ) ) {
$cptui_post_types = cptui_get_post_type_slugs();$query->set(
‘post_type’,
array_merge(
array( ‘post’ ),
$cptui_post_types
)
);
}
}
add_filter( ‘pre_get_posts’, ‘my_cptui_add_post_types_to_archives’ );/* Stop Adding Functions Below this Line */
?>So far, so good. I just have one remaining problem: in the tag archive, the layout/styling of my custom post types doesn’t look the same as the layout of my posts. In hopes of fixing the problem, I created an archive-{posttype}.php file, filled it with all the same code found in my archive.php file, and inserted it into my child theme.
But the layout/styling of the custom post types still differs from the layout/styling of my posts in the tag archive. Would you happen to have a snippet of code that could solve this problem for me, so that my custom post types will use the same layout as my posts do in the tag archive? (I’m not skilled at php.) And if so, where would I put the snippet?
Many thanks!
The page I need help with: [log in to see the link]
- The topic ‘CPT Archive Question’ is closed to new replies.