Site logo

Archived topic

Display Related Posts by Tag

3 replies · Started by webyogi on June 12, 2021

Viewing posts 1–4 of 4

Hi David,

Please can you provide some guidance on how i can modify your "#2 Hook: Related Posts" PHP code to show Related Posts by TAGS instead of CATEGORY on the Blog Post page.

https://gpsites.co/merch/the-single-post/

Thanks.

Hi David,

Thanks so much. I had a stab at it but Tom's is way better.

You guys are too good!

<div class="wpsp-related-posts  grid-container">
	<h3><strong>RELATED POSTS</strong></h3>
<?php    
if ( is_single() ) {
        $tags =  get_the_tags();
        $tags_list = [];
        foreach ($tags as $tag)
            $tags_list[] = $tag->slug;
            //$tags_list[] = $tag->term_id;
        $tag_string = implode( ', ', $tags_list);
    } else {
        $tag_string = get_tag( get_query_var( 'tag' ) );
    }
    $list = get_page_by_title( 'Related Posts', 'OBJECT', 'wp_show_posts' );
    $setting = 'tax_term="' . $tag_string . '"';
    wpsp_display( $list->ID, $setting);
?>
</div>

Glad we could be of help

This archived topic is closed to new replies.