- This topic has 9 replies, 4 voices, and was last updated 5 years, 4 months ago by
Tom.
-
AuthorPosts
-
December 2, 2020 at 6:48 am #1563695
Dominik
Hi there,
we have created several custom post types and are wondering how we get the featured image and the text excerpt for those posts?
We added the custom post types using the childs functions.php with register_post_type.
Thanks in advance,
DominikDecember 2, 2020 at 10:36 am #1564274Leo
StaffCustomer SupportHi there,
The featured image option should inherit the settings in the customizer:
https://docs.generatepress.com/article/adjusting-the-featured-images/Or do you want the setting to be different in the customizer and the CPT?
As for the excerpt, try this snippet:
https://generatepress.com/forums/topic/cpt-in-search-results-with-no-read-button/#post-967510But replace
falsewithtrueDecember 3, 2020 at 12:15 am #1565095Dominik
Hi Leo,
the settings should be the same as stated in the customizer. But when I add a new post in my CPT, I do not have the option for adding a featured image.
This is my code:
/* --------------------------------------------------------- Custom Post Types */ function create_posttype() { register_post_type( 'erlebnisse', array( 'labels' => array( 'name' => __( 'Erlebnisse' ), 'singular_name' => __( 'Erlebnis' ) ), 'taxonomies' => array( 'art' ), 'public' => true, 'has_archive' => false, 'menu_position' => 5, 'rewrite' => array('slug' => 'natur-erleben', "with_front" => false), 'show_in_rest' => true, 'menu_icon' => 'dashicons-palmtree', ) ); register_post_type( 'angebote', array( 'labels' => array( 'name' => __( 'Angebote' ), 'singular_name' => __( 'Angebot' ) ), 'taxonomies' => array( 'art' ), 'public' => true, 'has_archive' => false, 'menu_position' => 4, 'rewrite' => array('slug' => 'areal-und-angebote', "with_front" => false), 'show_in_rest' => true, 'menu_icon' => 'dashicons-carrot', ) ); } add_action( 'init', 'create_posttype'); function createCustomTaxonomy() { $bereicheLabels = array( 'name' => _x( 'Erlebnisse', 'taxonomy general name' ), 'singular_name' => _x( 'Art', 'taxonomy singular name' ), 'search_items' => __( 'Art Suchen' ), 'all_items' => __( 'Alle Arten' ), 'parent_item' => __( 'Eltern Art' ), 'parent_item_colon' => __( 'Eltern Art:' ), 'edit_item' => __( 'Art Bearbeiten' ), 'update_item' => __( 'Update Art' ), 'add_new_item' => __( 'Art hinzufügen' ), 'new_item_name' => __( 'Neue Art Name' ), 'menu_name' => __( 'Arten' ), ); register_taxonomy('art',array('erlebnis'), array( 'hierarchical' => true, 'labels' => $bereicheLabels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'erlebnisart' ), )); $artenLabels = array( 'name' => _x( 'Angebote', 'taxonomy general name' ), 'singular_name' => _x( 'Art', 'taxonomy singular name' ), 'search_items' => __( 'Art Suchen' ), 'all_items' => __( 'Alle Arten' ), 'parent_item' => __( 'Eltern Art' ), 'parent_item_colon' => __( 'Eltern Art:' ), 'edit_item' => __( 'Art Bearbeiten' ), 'update_item' => __( 'Update Art' ), 'add_new_item' => __( 'Art hinzufügen' ), 'new_item_name' => __( 'Neue Art Name' ), 'menu_name' => __( 'Arten' ), ); register_taxonomy('art',array('angebot'), array( 'hierarchical' => true, 'labels' => $artenLabels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'angebotsart' ), )); } add_action( 'init', 'createCustomTaxonomy', 0 ); add_filter( 'generate_show_excerpt', function( $show ) { if ( is_post_type_archive( 'Erlebnisse' ) || ( is_search() && 'Erlebnisse' === get_post_type() ) ) { return true; } return $show; } );December 3, 2020 at 4:41 am #1565474David
StaffCustomer SupportHi there,
see here for the register_post_type arguments:
https://developer.wordpress.org/reference/functions/register_post_type/
You could add this argument to include the thumbnail:
'supports' => array('thumbnail')December 9, 2020 at 5:20 am #1572711Dominik
Hi David,
as soon as I add the line, the gutenberg editor disappears. I have made a Screenshot
My goal is to get all the settings (with featured image, block editor etc.) in my custom post types identical to the standard posts of generatepress.
Thanks for your efforts
DominikDecember 9, 2020 at 8:26 am #1573109David
StaffCustomer SupportOdd, can you share your entire code with that argument in place? Maybe its missing a comma after it ?
December 11, 2020 at 5:26 am #1575904Dominik
Sure 🙂
function create_posttype() { register_post_type( 'erlebnisse', array( 'labels' => array( 'name' => __( 'Erlebnisse' ), 'singular_name' => __( 'Erlebnis' ) ), 'taxonomies' => array( 'art' ), 'public' => true, 'has_archive' => false, 'menu_position' => 5, 'rewrite' => array('slug' => 'natur-erleben', "with_front" => false), 'show_in_rest' => true, 'menu_icon' => 'dashicons-palmtree', 'supports' => array('thumbnail'), ) ); register_post_type( 'angebote', array( 'labels' => array( 'name' => __( 'Angebote' ), 'singular_name' => __( 'Angebot' ) ), 'taxonomies' => array( 'art' ), 'public' => true, 'has_archive' => false, 'menu_position' => 4, 'rewrite' => array('slug' => 'areal-und-angebote', "with_front" => false), 'show_in_rest' => true, 'menu_icon' => 'dashicons-carrot', 'supports' => array('thumbnail'), ) ); } add_action( 'init', 'create_posttype'); function createCustomTaxonomy() { $bereicheLabels = array( 'name' => _x( 'Erlebnisse', 'taxonomy general name' ), 'singular_name' => _x( 'Art', 'taxonomy singular name' ), 'search_items' => __( 'Art Suchen' ), 'all_items' => __( 'Alle Arten' ), 'parent_item' => __( 'Eltern Art' ), 'parent_item_colon' => __( 'Eltern Art:' ), 'edit_item' => __( 'Art Bearbeiten' ), 'update_item' => __( 'Update Art' ), 'add_new_item' => __( 'Art hinzufügen' ), 'new_item_name' => __( 'Neue Art Name' ), 'menu_name' => __( 'Arten' ), ); register_taxonomy('art',array('erlebnis'), array( 'hierarchical' => true, 'labels' => $bereicheLabels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'erlebnisart' ), )); $artenLabels = array( 'name' => _x( 'Angebote', 'taxonomy general name' ), 'singular_name' => _x( 'Art', 'taxonomy singular name' ), 'search_items' => __( 'Art Suchen' ), 'all_items' => __( 'Alle Arten' ), 'parent_item' => __( 'Eltern Art' ), 'parent_item_colon' => __( 'Eltern Art:' ), 'edit_item' => __( 'Art Bearbeiten' ), 'update_item' => __( 'Update Art' ), 'add_new_item' => __( 'Art hinzufügen' ), 'new_item_name' => __( 'Neue Art Name' ), 'menu_name' => __( 'Arten' ), ); register_taxonomy('art',array('angebot'), array( 'hierarchical' => true, 'labels' => $artenLabels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'angebotsart' ), )); } add_action( 'init', 'createCustomTaxonomy', 0 ); add_filter( 'generate_show_excerpt', function( $show ) { if ( is_post_type_archive( 'Erlebnisse' ) || ( is_search() && 'Erlebnisse' === get_post_type() ) ) { return true; } return $show; } );December 11, 2020 at 7:18 pm #1576892Tom
Lead DeveloperLead DeveloperHi there,
You need to add support for the editor as well:
'supports' => array( 'editor', 'thumbnail' ),You can read more about the supports arg here: https://developer.wordpress.org/reference/functions/register_post_type/
Hope it helps!
December 14, 2020 at 1:02 am #1579455Dominik
Hi Tom,
THANKS! Works 😀
Best wishes,
DominikDecember 14, 2020 at 11:04 am #1580477Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.