Shortcode for CPT tags

This topic contains 4 replies, has 3 voices, and was last updated by  Yael 5 years, 7 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #447293

    Yael
    Lifetime Member
    Post count: 13

    Hi,
    I would like to display the tags of a details page in a different place other than under the slideshow images.
    Which shortcode can I use in order to display the tags of each listing in another field / widget?

    Or, where can I find the html template of CPT in order to move the location of the tags somewhere else on that CPT page?

    Thanks!!!

    #447444

    Alex Rollin
    Moderator
    Post count: 27815

    Hello,

    Moving tags is only possible with code snippets in V1.

    With V2, yes, there is a shortcode that can be used, and tags can be shown with the Output Locations feature.

    
    
    
    [gd_post_meta key="post_tags"]
    

    Use the shortcode builder on a WP Page to see all the params available.

    #447449

    Yael
    Lifetime Member
    Post count: 13

    Thank you Alex!

    I think I have the V1 since the code isn’t working.

    I’m not sure which code snippet to add instead.
    Where can I find information about that?

    #447454

    Kiran
    Moderator
    Post count: 7069

    Hi Yael,

    I would like to display the tags of a details page in a different place other than under the slideshow images.

    Please use following code snippet and then use shortcode: [gd_snippet_sc_detail_tags].

    
    
    /*
     * Usage: [gd_snippet_sc_detail_tags]
     */
    function gd_snippet_sc_detail_tags( $attr, $content = '' ) {
    	global $post, $preview;
    
    	$html = '';
    
    	if ( ! empty( $post ) && ! empty( $post->post_tags ) && ( geodir_is_page( 'detail' ) || geodir_is_page( 'preview' ) ) ) {
    		$post_tags = trim( $post->post_tags, "," );
    		$post_tags = explode( ",", $post_tags );
    		
    		if ( ! empty( $post_tags ) ) {
    			$is_backend_preview = (is_single() && !empty($_REQUEST['post_type']) && !empty($_REQUEST['preview']) && !empty($_REQUEST['p'])) && is_super_admin() ? true : false;
    			$post_type = $preview && ! $is_backend_preview ? $post->listing_type : $post->post_type;
    			$post_type_info = get_post_type_object( $post_type );
    			$post_type_name = __( $post_type_info->labels->singular_name, 'geodirectory' );
    
    			$tag_links = array();
    			foreach ( $post_tags as $post_tag ) {
    				$post_tag = trim( $post_tag );
    
    				$term_exists = term_exists( $post_tag, $post_type . '_tags' );
    				if ( ! empty( $term_exists ) && ! empty( $term_exists['term_id'] ) ) {
                        $term = get_term_by( 'id', $term_exists['term_id'], $post_type . '_tags' );
                    } else {
                        $term = get_term_by( 'name', $post_tag, $post_type . '_tags' );
                    }
    
    				if ( ! empty( $term ) && ! is_wp_error( $term ) ) {
    					$tag_links[] = apply_filters( 'geodir_details_taxonomies_tag_link', '<a href="' . esc_attr( get_term_link( $term->term_id, $term->taxonomy ) ) . '">' . $term->name . '</a>', $term );
    				}
    			}
    
    			if ( ! empty( $tag_links ) ) {
    				$tag_links = implode( ', ', $tag_links );
    				$html = wp_sprintf( __( '%s Tags: %s', 'geodirectory' ), $post_type_name, $tag_links );
    			}
    		}
    	}
    
        return $html;
    }
    add_shortcode( 'gd_snippet_sc_detail_tags', 'gd_snippet_sc_detail_tags' );

    Thanks,
    Kiran

    #447469

    Yael
    Lifetime Member
    Post count: 13

    Kiran, that works perfectly!
    Thank you so much!!!

Viewing 5 posts - 1 through 5 (of 5 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket