[Resolved] Customized Post Meta Tags

Home Forums Support [Resolved] Customized Post Meta Tags

Home Forums Support Customized Post Meta Tags

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2003047
    Jeff

    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?

    #2003138
    David
    Staff
    Customer Support

    Hi 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

    #2005652
    Jeff

    So 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’,
    );
    } );

    #2005658
    Elvin
    Staff
    Customer Support

    Hi 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 ) to if ( 'post_columnist' === $item ).

    #2005663
    Jeff

    That worked – thanks.

    #2005670
    Elvin
    Staff
    Customer Support

    No problem. ๐Ÿ˜€

    #2005674
    Jeff

    One 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.

    #2005676
    Elvin
    Staff
    Customer Support

    On 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', '', ', '  );
        }
    } );
    #2005728
    Jeff

    That worked great.

    #2005778
    Elvin
    Staff
    Customer Support

    No problem. ๐Ÿ˜€

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.