- This topic has 14 replies, 3 voices, and was last updated 3 years, 3 months ago by
Tom.
-
AuthorPosts
-
October 16, 2019 at 8:22 am #1036401
Heather
Hi,
I’ve created a custom post type for events within the theme’s functions.php, and the new post type shows up in my dashboard and I can create and view posts, however, it’s archive page does not accept the layout I input from Appearance > Customize > Layout > Blog.
It also seems that, even though all my categories show up to be added to these posts, it does not register them – ie: I add a category of “cool” to my event post, but if i go to /blog/category/cool where all the posts with that category exist, it does not show up. Same thing with tags.
Is there a way to fix this?
October 16, 2019 at 2:20 pm #1036672Heather
More specifically, it seems like my archive page is not being wrapped in the “generate-columns-container” class that exists after the <main>. Is there a way for me to add this? See attached
October 16, 2019 at 5:28 pm #1036777David
StaffCustomer SupportHi there,
can you link me to the site so i can take a look?
You can edit your original topic and use the Site URL field to share it privately.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 17, 2019 at 11:59 am #1037490Heather
Unfortunately I am working off of local and doing work for a client so I have no way of linking. Here is my code in my functions.php however:
//Custom post type - event // register custom post type to work with function lc_create_post_type() { // set up labels $labels = array ( 'name' => 'Events', 'singular_name' => 'Event', 'add_new' => 'Add New Event', 'add_new_item' => 'Add New Event', 'edit_item' => 'Edit Event', 'new_item' => 'New Event', 'all_items' => 'All Events', 'view_item' => 'View Event', 'search_items' => 'Search Events', 'not_found' => 'No Events Found', 'not_found_in_trash' => 'No Events found in Trash', 'parent_item_colon' => '', 'menu_name' => 'Events', ); //register post type register_post_type ( 'event', array( 'labels' => $labels, 'has_archive' => 'blog/events', 'public' => true, 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail','page-attributes' ), 'taxonomies' => array( 'post_tag', 'category' ), 'exclude_from_search' => false, 'capability_type' => 'post', 'rewrite' => true, ) ); } add_action( 'init', 'lc_create_post_type' );
October 17, 2019 at 8:01 pm #1037730Tom
Lead DeveloperLead DeveloperHi there,
This might help: https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-type
Let me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentOctober 21, 2019 at 1:13 pm #1040686Heather
Hi,
This worked great! Thank you!
Im now having a couple of different issues –
1. I would like the start and end time of the event to be displayed on the archive page/be able to isolate that information via a query or shortcode. I noticed it is not being displayed as part of the post; do I need to update something in the single.php and archive.php? see attached for photo
2. I noticed although my categories come up in the post to be selected, but when I go to the archive page for that category, the event post does not show up. Is there additional code I need to add to my functions.php?
see my updated code://Custom post type - event // register custom post type to work with function lc_create_post_type() { // set up labels $labels = array ( 'name' => 'Events', 'singular_name' => 'Event', 'add_new' => 'Add New Event', 'add_new_item' => 'Add New Event', 'edit_item' => 'Edit Event', 'new_item' => 'New Event', 'all_items' => 'All Events', 'view_item' => 'View Event', 'search_items' => 'Search Events', 'not_found' => 'No Events Found', 'not_found_in_trash' => 'No Events found in Trash', 'parent_item_colon' => '', 'menu_name' => 'Events', ); //register post type register_post_type ( 'event', array( 'labels' => $labels, 'has_archive' => true, 'public' => true, 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail','page-attributes' ), 'taxonomies' => array( 'post_tag', 'category' ), 'exclude_from_search' => false, 'capability_type' => 'post', 'rewrite' => array( 'slug' => 'events' ), ) ); } add_action( 'init', 'lc_create_post_type' ); add_filter( 'generate_blog_columns','tu_portfolio_columns' ); function tu_portfolio_columns( $columns ) { if ( is_post_type_archive( 'event' ) ) { return true; } return $columns; } add_filter( 'generate_blog_get_column_count','tu_search_column_count' ); function tu_search_column_count( $count ) { if ( is_search() ) { return 33; } return $count; }
October 21, 2019 at 5:01 pm #1040800Tom
Lead DeveloperLead DeveloperHi there,
1. Where do you want your custom field to show up, exactly? You’ll likely need to hook it into the post using our Hook Elements: https://docs.generatepress.com/article/hooks-element-overview/
2. Just so I understand right, you’re adding regular categories to our custom post type, but the posts aren’t showing up in those category archives? Maybe this will help?: https://wordpress.stackexchange.com/questions/251939/posts-from-custom-post-type-not-shown-in-category-archive
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentOctober 22, 2019 at 12:30 pm #1041713Heather
Is there no way to add code to one of the .php files so that it shows up everywhere? I want it to show up under the event post title.
October 22, 2019 at 6:08 pm #1041833Tom
Lead DeveloperLead DeveloperYou could try the
after_entry_title
hook in a Hook Element: https://docs.generatepress.com/article/hooks-element-overview/Then just apply it to your events/archives in the Display Rules.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentOctober 23, 2019 at 10:46 am #1042688Heather
I was able to get the shortcode to show up with that hook, so that will do for now.
For the categories, unfortunately the info on that link did not work. But yes, you have the right idea – The events page comes with it’s own categories I think, but I have a set of 7 cats that also show up when making an event post that I can select. But, even though these categories are the same, the event posts do not show up in the selected categories.
What I am trying to do is display event information in a shortcode based on a category and tag, so the tag is always supposed to be ‘event’, and then a specific post will come up based on the category filter, so [display_posts=”1″ category=”happy” tag=”event”]. But that happy category that already exists does not register for any cpt.
October 23, 2019 at 10:52 am #1042690Heather
Or, given the code below, if I could isolate the custom post type, it probably wouldn’t matter because then I can base the short code pull off the category and/or tag on the custom post type.
ie: [display_posts=”1″ post_type=”events” category=”happy”]
or something like that
function lc_create_post_type() { // set up labels $labels = array ( 'name' => 'Events', 'singular_name' => 'Event', 'add_new' => 'Add New Event', 'add_new_item' => 'Add New Event', 'edit_item' => 'Edit Event', 'new_item' => 'New Event', 'all_items' => 'All Events', 'view_item' => 'View Event', 'search_items' => 'Search Events', 'not_found' => 'No Events Found', 'not_found_in_trash' => 'No Events found in Trash', 'parent_item_colon' => '', 'menu_name' => 'Events', ); //register post type register_post_type ( 'event', array( 'labels' => $labels, 'has_archive' => true, 'public' => true, 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail','page-attributes' ), 'taxonomies' => array( 'post_tag', 'category' ), 'exclude_from_search' => false, 'capability_type' => 'post', 'rewrite' => array( 'slug' => 'events' ), ) ); } add_action( 'init', 'lc_create_post_type' ); add_shortcode('field', 'shortcode_field'); function shortcode_field($atts){ extract(shortcode_atts(array( 'post_id' => NULL, ), $atts)); if(!isset($atts[0])) return; $field = esc_attr($atts[0]); global $post; $post_id = (NULL === $post_id) ? $post->ID : $post_id; return get_post_meta($post_id, $field, true); } add_filter( 'generate_blog_columns','tu_portfolio_columns' ); function tu_portfolio_columns( $columns ) { if ( is_post_type_archive( 'event' ) ) { return true; } return $columns; } add_filter( 'generate_blog_get_column_count','tu_search_column_count' ); function tu_search_column_count( $count ) { if ( is_search() ) { return 33; } return $count; }
October 23, 2019 at 12:08 pm #1042725Heather
Nevermind, post_type is already able to be used within display-posts, and I can isolate the category selected of the cpt as well.
October 23, 2019 at 7:39 pm #1042931Tom
Lead DeveloperLead DeveloperGlad you got that sorted – is there anything else you’re stuck on? π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentOctober 25, 2019 at 7:51 am #1044389Heather
I think I am ok for now, I will mark this as resolved and if something else comes up along the same vein I will create another specialized ticket.
Thanks for the help.
October 25, 2019 at 9:53 am #1044489Tom
Lead DeveloperLead DeveloperNo problem π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.