Site logo

[Support request] Add meta to custom post type

Home Forums Support [Support request] Add meta to custom post type

Home Forums Support Add meta to custom post type

Viewing 10 posts - 16 through 25 (of 25 total)
  • Author
    Posts
  • #2042012
    Elvin
    Staff
    Customer Support

    Ah I see what you mean.

    Can you tell us how and where you want it to be displayed?

    Do you want it to appear on the Header Element? If that’s the case, you’ll need a shortcode to display the taxonomy term links.

    We can write a quick shortcode for this if this is the case. Let us know.

    #2042276
    Hilton

    This is the place I want to be displayed (after the content).
    https://bit.ly/3dsK9X3

    The same place as regular posts https://bit.ly/3dtYTVs

    Thanks

    #2042286
    Hilton

    One more thing, regarding placement, I don’t think you need to worry because we can hook it using GP’s “Elements” like we did here (generate_after_content) Elements: https://bit.ly/3Iwdv4R frontend: https://bit.ly/31BVyRx

    Thanks

    #2043022
    Elvin
    Staff
    Customer Support

    Ah yes that’s right.

    In that case, I think what you need is the shortcode now.

    Try Tom’s shortcode here – https://generatepress.com/forums/topic/help-with-template-tags-for-custom-post-type/#post-1540350

    for the term attribute, place the slug of your custom category.

    #2043034
    Hilton

    Hi Elvin,

    It worked, the categories are being displayed. But the links are not active as you can see here https://bit.ly/31BVyRx . How can I activate the respective links?

    Thanks

    #2043040
    Elvin
    Staff
    Customer Support

    ah right, the shortcode specifically strips the link.

    Let’s modify the shortcode a bit:

    Try this modification:

    add_shortcode( 'my_terms', function( $atts ) {
        $options = shortcode_atts( array(
            'term' => 'category',
        ), $atts );
    
        $terms = get_the_term_list( get_the_ID(), $options['term'], '', ', ', '' );
    
        if ( ! is_wp_error( $terms ) ) {
            return $terms;
        }
    } );
    #2043045
    Hilton

    Now it worked! The only pending issue is to put it in the same format as the normal posts as you can see here in this print https://bit.ly/3IqVp4i and in this post for example https://bit.ly/3lNnZDv .

    I think it uses the <span class=”cat-links”>

    Thanks

    #2043049
    Elvin
    Staff
    Customer Support

    We can modify it further to wrap it in that element.

    Example:

    add_shortcode( 'my_terms', function( $atts ) {
        $options = shortcode_atts( array(
            'term' => 'category',
        ), $atts );
    
        $terms = get_the_term_list( get_the_ID(), $options['term'], '', ', ', '' );
    
        if ( ! is_wp_error( $terms ) ) {
            return sprintf(
    					'<span class="cat-links">%3$s<span class="screen-reader-text">%1$s </span>%2$s</span> ',
    					esc_html_x( 'Categories', 'Used before category names.', 'generatepress' ),
    					$terms,
    					apply_filters( 'generate_inside_post_meta_item_output', '', 'categories' )
    				);
        }
    } );

    I’ve included the icon as well.

    #2043066
    Hilton

    Elvin, thank you very much! It worked here. Excellent!

    #2043068
    Elvin
    Staff
    Customer Support

    No problem. Let us know if this is resolved or if you need further help. 😀

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