Archived topic
Add meta to custom post type
24 replies · Started by Hilton on December 7, 2021
Hi, I created a custom post type that has its own categories. I would like to know how I can display them below the custom posts.
This is the function I use:
function mefvideos_init() {
// set up product labels
$labels = array(
'name' => 'Vídeos',
'singular_name' => 'Vídeo',
'add_new' => 'Add New Vídeo',
'add_new_item' => 'Add New Vídeo',
'edit_item' => 'Edit Vídeo',
'new_item' => 'New Vídeo',
'all_items' => 'All Vídeos',
'view_item' => 'View Vídeo',
'search_items' => 'Search Vídeos',
'not_found' => 'No Vídeos Found',
'not_found_in_trash' => 'No Vídeos found in Trash',
'parent_item_colon' => '',
'menu_name' => 'Vídeos',
);
// register post type
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'videos'),
'query_var' => true,
'menu_icon' => 'dashicons-randomize',
'supports' => array(
'title',
'editor',
'excerpt',
'trackbacks',
'custom-fields',
'comments',
'revisions',
'thumbnail',
'author',
'page-attributes'
)
);
register_post_type( 'videos', $args );
// register taxonomy
register_taxonomy('videos_category', 'videos', array('hierarchical' => true, 'label' => 'Category', 'query_var' => true, 'rewrite' => array( 'slug' => 'videos-category' )));
}
add_action( 'init', 'mefvideos_init' );
Hi Hilton,
Try these snippet to add meta to CPT:
https://docs.generatepress.com/article/generate-footer-meta-post-types/
https://docs.generatepress.com/article/generate_entry_meta_post_types/
Let me know if this helps :)
Hi,
I tried adding this to my functions.php, but didn't work
add_filter( 'generate_footer_meta_videos_types', function( $types ) {
$types[] = 'videos';
return $types;
} );
This is the page https://bit.ly/31BVyRx
You are not supposed to change the filter name: generate_footer_meta_post_types.
Can you give it another try?
Just to complement, this is the function I am using for creating CPT
// Video Custom Post Type
function mefvideos_init() {
// set up video labels
$labels = array(
'name' => 'Vídeos',
'singular_name' => 'Vídeo',
'add_new' => 'Add New Vídeo',
'add_new_item' => 'Add New Vídeo',
'edit_item' => 'Edit Vídeo',
'new_item' => 'New Vídeo',
'all_items' => 'All Vídeos',
'view_item' => 'View Vídeo',
'search_items' => 'Search Vídeos',
'not_found' => 'No Vídeos Found',
'not_found_in_trash' => 'No Vídeos found in Trash',
'parent_item_colon' => '',
'menu_name' => 'Vídeos',
);
// register post type
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'videos'),
'query_var' => true,
'menu_icon' => 'dashicons-video-alt3',
'supports' => array(
'title',
'editor',
'excerpt',
'trackbacks',
'custom-fields',
'comments',
'revisions',
'thumbnail',
'author',
'page-attributes'
)
);
register_post_type( 'videos', $args );
// register taxonomy
register_taxonomy('videos_category', 'videos', array('hierarchical' => true, 'label' => 'Category', 'query_var' => true, 'rewrite' => array( 'slug' => 'videos-category' )));
}
add_action( 'init', 'mefvideos_init' );
//adicionar meta tags abaixo do video
add_filter( 'generate_footer_meta_post_types', function( $types ) {
$types[] = 'videos';
return $types;
} );
I was actually using the correct function but I wrote the wrong one here
add_filter( 'generate_footer_meta_post_types', function( $types ) {
$types[] = 'videos';
return $types;
} );
Then it should work.
Can you try clear cache and disable cache plugin?
I disabled cache, but it is not working.
I don't know if you noticed the function I put here, which created the CPT. Maybe looking at it, especially at the end, you'll know why the proposed solution isn't working.
So it's working now?
No
Hi there,
The slug being added may be incorrect. Can you link us to a sample single post page of the mentioned CPT?
Can you share the customizer settings set for single post pages on Appearance > Customize > Layout > Blog?
To be specific, here are the things to check - https://share.getcloudapp.com/BluD9Xe2
Are all of them checked?
I see that you're using a Header element. Header elements can disable the default location of the entry meta items if you use the template tags.
Say for example, if you use {{post_author}} on the Header Element, the meta author will be moved from the default to the Header element.
Hi Elvin,
They are marked as you can see here https://www.dropbox.com/s/d430ivdra5jqznh/Captura%20de%20Tela%202021-12-08%20%C3%A0s%2003.10.33.png?dl=0
I think the confusion is that I want to display a custom category and not post categories. Example of custom categories:
https://bit.ly/3EDqPCd
https://bit.ly/30601eR
In this video you can have a better idea of my needs.
Thanks