-
damnsharp
Good morning, I’ve created a CPT with the CPT UI software.
When I create a new post and add a category and some tags to it, that works.
But when I show the new post no category or tags are displayed.
The standard WP post does show category and tags (I’ve enabled them in customizer GP settings).What could I forget? Thanks in advance.
(oh of course I first tried to find a solution on the forum but could not find any or the topic was different)
-
Hi there,
This should help:
https://docs.generatepress.com/article/generate_entry_meta_post_types/
https://docs.generatepress.com/article/generate-footer-meta-post-types/Let us know 🙂
-
damnsharp
Indeed Tom! Thank you very much.
-
damnsharp
Oh Tom, one more thing, when I now click on the category or tag nothing shows up. Is that something what I best can ask CPT UI?
-
I believe your CPT would have to be configured to have archives for that to work. Do you want them to have archives? If so, CPT UI should have that option.
If not, we should be able to remove the links.
Let me know 🙂
-
damnsharp
Hi Tom,
I decided to create the CPT with ACF because I have that software also installed.
But with the code you’ve showed me within the links I don’t see the taxonomies below of the post.Post type declared:
“Recepten” (Recipes)
Taxonomies declared:
“Recept personen” (Recipe persons)
“Recept typen” (Recipe types)add_filter( 'generate_entry_meta_post_types', function( $types ) { $types[] = 'recepten'; return $types; } ); add_filter( 'generate_footer_meta_post_types', function( $types ) { $types[] = 'recepten'; return $types; } );
-
The post type slug is
recept
notrecepten
.
https://app.screencast.com/40Rf2AVLTMsV5 -
damnsharp
Indeed @Ying now it works with the post type but not with the custom taxonomies created with ACF.
Is there also a GP filter for?So I see now that e.g. I created the recipe post but I don’t see that the recipe is a main-meal.
Thanks!
-
Hi there,
you would need to hook in your own function to display the custom terms for example:
// add a post meta type called my-custom-taxonomy add_filter( 'generate_post_meta_items', function( $types ) { $types[] = 'my-custom-taxonomy'; return $types; } ); // Add a function to return the my_custom_taxonomy terms for the my-custom-taxonomy item add_action( 'generate_post_meta_items', function( $item ) { if ( 'my-custom-taxonomy' === $item ) { echo get_the_term_list( get_the_ID(), 'my_custom_taxonomy', '', ', ' ); } } ); // tell GP to include 'my-custom-taxonomy' in footer meta add_filter( 'generate_footer_entry_meta_items', function() { return array( 'date', 'tags', 'categories', 'my-custom-taxonomy', ); } );
Alternatively you can sue a block element to build your own custom post meta for a no ( less ) code solution
-
damnsharp
Thank you David for reply but I can see it’s more difficult than I thought.
Adding the post meta with the filters was easy but transforming your code to something that works for me is a challenge.
So showing the recipe-type and recipe-persons is not so easy I understand.
I will try to find another way. -
Do you use the block editor ?
As you can use a GP Block Element to build that layout.If not, what are the custom taxonomy term names ? And I can edit that code to match them
-
damnsharp
You’re too kind David! I have a simple post so without a GP Block Element but maybe I should use it.
taxonomy key: “recept-persoon” (how many persons)
and taxonomy key “recept-type” (what kind of meal)and they are attached to the CPT “recept”.
I tried it with your code but nothing showed up.
-
Try this:
// add new types for custom taxonomies add_filter( 'generate_post_meta_items', function( $types ) { $types[] = 'recept-persoon'; $types[] = 'recept-type'; return $types; } ); // output a list of custom taxonomy terms add_action( 'generate_post_meta_items', function( $item ) { if ( 'recept-persoon' === $item ) { echo get_the_term_list( get_the_ID(), 'recept-persoon', '', ', ' ); } if ( 'recept-type' === $item ) { echo get_the_term_list( get_the_ID(), 'recept-type', '', ', ' ); } } ); // tell GP to include list of custom taxonomies in footer meta add_filter( 'generate_footer_entry_meta_items', function() { return array( 'date', 'tags', 'categories', 'recept-persoon', 'recept-type', ); } );
-
damnsharp
Hi David, with the code it’s not working. The first code showed indeed the meta data of the post (date, user) but with the taxonomy code the whole post looked very strange. So I had to remove it.
See below the post normal:
The post with the latest code:
Post type:
Taxonomy 1:
Taxonomy 2:
-
The entry meta should not be affected, the items are being added to the footer meta which shows categories/tags in regular posts.
Can you enable the code so we can take another look?
-
damnsharp
Of course @Ying, great.
I’ve added the following code to functions.php
/* GeneratePress show meta fields with CPT UI */ add_filter( 'generate_entry_meta_post_types', function( $types ) { $types[] = 'my-post-type'; $types[] = 'recepten'; return $types; } ); add_filter( 'generate_footer_meta_post_types', function( $types ) { $types[] = 'my-post-type'; $types[] = 'recepten'; return $types; } ); /* GeneratePress show meta category and tag with CPT UI */ // add new types for custom taxonomies add_filter( 'generate_post_meta_items', function( $types ) { $types[] = 'recept-persoon'; $types[] = 'recept-type'; return $types; } ); // output a list of custom taxonomy terms add_action( 'generate_post_meta_items', function( $item ) { if ( 'recept-persoon' === $item ) { echo get_the_term_list( get_the_ID(), 'recept-persoon', '', ', ' ); } if ( 'recept-type' === $item ) { echo get_the_term_list( get_the_ID(), 'recept-type', '', ', ' ); } } ); // tell GP to include list of custom taxonomies in footer meta add_filter( 'generate_footer_entry_meta_items', function() { return array( 'date', 'tags', 'categories', 'recept-persoon', 'recept-type', ); } );
- You must be logged in to reply to this topic.