- This topic has 9 replies, 3 voices, and was last updated 2 years, 5 months ago by Elvin.
-
AuthorPosts
-
November 13, 2021 at 8:52 am #2003047Jeff
I have created two custom taxonomies called Publication and Columnist. I would like to display the values of these fields instead of the standard “author” tag used in each single post. Can you please advise me how to accomplish this?
November 13, 2021 at 10:36 am #2003138DavidStaffCustomer SupportHi there,
it takes a little code to register and display the custom taxonomy terms… Elvin provides an example here:
https://generatepress.com/forums/topic/cpt-tags-are-not-showing-why/#post-1879998
November 15, 2021 at 4:33 pm #2005652JeffSo I tried to follow the example you provided and it is not working. Here is an example of what I tried.
`<?php
/**
* GeneratePress child theme functions and definitions.
*
* Add your custom PHP in this file.
* Only edit this file if you have direct access to it on your server (to fix errors if they happen).
*/add_filter( ‘generate_entry_meta_post_types’, function( $types ) {
$types[] = ‘columnist’;return $types;
} );add_action( ‘generate_post_meta_items’, function( $item ) {
if ( ‘portfolio-tags’ === $item ) {
echo get_the_term_list( get_the_ID(), ‘post_columnist’, ”, ‘, ‘ );
}
} );add_filter( ‘generate_header_entry_meta_items’, function() {
return array(
‘date’,
‘tags’,
‘post_columnist’,
);
} );November 15, 2021 at 4:39 pm #2005658ElvinStaffCustomer SupportHi Jeff,
On this line:
add_action( 'generate_post_meta_items', function( $item ) { if ( 'portfolio-tags' === $item ) { echo get_the_term_list( get_the_ID(), 'post_columnist', ", ', ' ); } } );
Try changing the line
if ( 'portfolio-tags' === $item )
toif ( 'post_columnist' === $item )
.November 15, 2021 at 4:49 pm #2005663JeffThat worked – thanks.
November 15, 2021 at 5:00 pm #2005670ElvinStaffCustomer SupportNo problem. ๐
November 15, 2021 at 5:04 pm #2005674JeffOne more question – how can I put some text between values?
Right now, my code is as follows:
<?php /** * GeneratePress child theme functions and definitions. * * Add your custom PHP in this file. * Only edit this file if you have direct access to it on your server (to fix errors if they happen). */ add_filter( 'generate_entry_meta_post_types', function( $types ) { $types[] = 'publication'; return $types; } ); add_action( 'generate_post_meta_items', function( $item ) { if ( 'post_publication' === $item ) { echo get_the_term_list( get_the_ID(), 'post_publication', '', ', ' ); } } ); add_filter( 'generate_entry_meta_post_types', function( $types ) { $types[] = 'columnist'; return $types; } ); add_action( 'generate_post_meta_items', function( $item ) { if ( 'post_columnist' === $item ) { echo get_the_term_list( get_the_ID(), 'post_columnist', '', ', ' ); } } ); add_filter( 'generate_header_entry_meta_items', function() { return array( 'date', 'tags', 'post_publication', 'post_columnist', ); } );
It generates this:
November 15, 2021 Fox NewsStaff
I want it to display like this:
November 15, 2021 from Fox News by Staff
Basically adding the word from in front of the publication and the word by in front of the columnist.
November 15, 2021 at 5:07 pm #2005676ElvinStaffCustomer SupportOn this item:
add_action( 'generate_post_meta_items', function( $item ) { if ( 'post_columnist' === $item ) { echo get_the_term_list( get_the_ID(), 'post_columnist', '', ', ' ); } } );
You can try adding a “by” text.
Example:
add_action( 'generate_post_meta_items', function( $item ) { if ( 'post_columnist' === $item ) { echo ' by '.get_the_term_list( get_the_ID(), 'post_columnist', '', ', ' ); } } );
November 15, 2021 at 6:40 pm #2005728JeffThat worked great.
November 15, 2021 at 8:34 pm #2005778ElvinStaffCustomer SupportNo problem. ๐
-
AuthorPosts
- You must be logged in to reply to this topic.