- This topic has 9 replies, 2 voices, and was last updated 4 years, 9 months ago by Tom.
-
AuthorPosts
-
July 9, 2019 at 5:40 pm #953474Roger
Hi, I’ve created a custom post type of ‘hunt’ using the following code:
if ( ! function_exists( 'create_post_type' ) ) : function create_post_type() { register_post_type( 'hunt', array( 'labels' => array( 'name' => __( 'Hunts' ), 'singular_name' => __( 'Hunt' ), ), 'public' => true, 'supports' => array ( 'title', 'editor', 'custom-fields', 'page-attributes', 'thumbnail', 'excerpt' ), // do you need all of these options? 'taxonomies' => array( 'category', 'post_tag' ), 'hierarchical' => true, 'menu_icon' => get_bloginfo( 'template_directory' ) . "/images/icon.png", 'rewrite' => array ( 'slug' => __( 'hunts' ) ) ) ); } add_action( 'init', 'create_post_type' ); endif;
And I’ve added the following filter so that this custom post type appears on the category page along with standard posts:
add_filter('pre_get_posts', 'query_post_type'); function query_post_type($query) { if( is_category() || is_tag()) { $post_type = get_query_var('post_type'); if($post_type) $post_type = $post_type; else $post_type = array('nav_menu_item', 'post', 'hunt'); $query->set('post_type',$post_type); return $query; } }
However, I’ve now lost the styling for the archive page that I set in the customizer and, the header element isn’t being applied to the custom post type. What am I doing wrong?
July 10, 2019 at 9:10 am #954156TomLead DeveloperLead DeveloperHi there,
1. What kind of styling? Columns? If so, this might help: https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-type
2. In the Display Rules for the Header Element, have you included your new post type?
July 10, 2019 at 9:36 am #954186RogerHi Tom,
1. Yes – the column settings that I’ve applied to the category page for standard posts and that I want to apply to the category page for my custom posts are as follows:
I’ve added the filter that you suggest but nothing has changed.
2. Yes, I’ve set it to display on the category archive for the custom post, but nothing is appearing.
July 10, 2019 at 5:21 pm #954428TomLead DeveloperLead Developer1. That filter is needed. Did you update the name of the cpt to look for?
2. Can you try “Hunt Category Archive” instead? That Display Rule will target single posts inside that category.
July 10, 2019 at 5:35 pm #954439RogerHi Tom,
1. Yes, I updated the cpt name, but it’s not working
2. I’ve changed the display location for the element to Hunt Category Archive, but still no joy.
I noticed that although in the Element itself it shows that ‘Hunt Category Archive’ has been selected, on the summary page for all Elements it shows ‘Post Category Archive’ which might suggest some sort of conflict/error.
Display Location in the Element itself:
All Elements list view:
July 11, 2019 at 9:36 am #955094TomLead DeveloperLead DeveloperSo it looks like you’re using a regular category taxonomy. What happens if you choose “Vancouver” along with “Post Category Archive”?
July 11, 2019 at 10:42 am #955163RogerJust gave that a try. Changing ‘Hunt Category Archive’ to ‘Post Category Archive’ in the Header Element fails to display the Header too.
July 11, 2019 at 9:03 pm #955538TomLead DeveloperLead DeveloperHmm, what is happening here..
What if you create a custom taxonomy for that CPT instead of using post categories?
July 12, 2019 at 12:10 pm #956206RogerOk. I created a custom taxonomy of ‘Cities’ for that CPT and set the Header Element to display for ‘Hunt City Archive – All Cities’ and we have lift off! Not sure why Elements didn’t like the combined taxonomy, but this will be fine.
I also adjusted the column filter and that’s all sorted too:
add_filter( 'generate_blog_columns','tu_portfolio_columns' ); function tu_portfolio_columns( $columns ) { if ( is_tax() ) { return true; } return $columns; }
Thanks for help troubleshooting ๐
July 12, 2019 at 3:26 pm #956328TomLead DeveloperLead DeveloperStrange, I’ll look into it.
Glad it’s all working now ๐
-
AuthorPosts
- You must be logged in to reply to this topic.