Display related post based on tag

wordpress related posts by tags and category
wordpress related posts by category
wordpress related posts without plugin
wordpress custom related posts
contextual related posts
get category related post
yet another related posts plugin
wordpress related posts plugin

I'm working on a music site which uses a lot of tags and categories per post. For example, on an artist's page the related posts display that artist's releases based on tags. I have tried adding the tag using Wordpress' post_type to the $args = array( -

'post_type' => 'releases'

but it hasn't worked.

For example, here is the complete code -

<div class="relatedposts">
            <h3>Releases by Artist</h3>
            <?php
                $orig_post = $post;
                global $post;
                $tags = wp_get_post_tags($post->ID);

                if ($tags) {
                $tag_ids = array();
                foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
                $args=array(
                'post_type' => 'releases',
                'tag__in' => $tag_ids,
                'post__not_in' => array($post->ID),
                'posts_per_page'=>4, // Number of related posts to display.
                'caller_get_posts'=>1
                );

                $my_query = new wp_query( $args );

                while( $my_query->have_posts() ) {
                $my_query->the_post();
                ?>

                <div class="relatedthumb">
                    <a rel="external" href="<? the_permalink()?>"><?php the_post_thumbnail(array(150,100)); ?><br />
                    <?php the_title(); ?>
                    </a>
                </div>

                <? }
                }
                $post = $orig_post;
                wp_reset_query();
                ?>
            </div>

I've followed a lot of other Stackoverflow posts and can't seem to get the right result. Where am I going wrong ?!

<section class="row related">
    <div class="row related-articles">
        <h2 class="related-title">Related Content</h2>
        <div class="relatedposts">
            <?php
        $orig_post = $post;
        global $post;
        $tags = wp_get_post_tags($post->ID);

        if ($tags) {
            $tag_ids = array();
        foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
            $args=array(
                'tag__in' => $tag_ids,
                'post__not_in' => array($post->ID),
                'posts_per_page'=>3, // Number of related posts to display.
                'caller_get_posts'=>1
            );

        $my_query = new wp_query( $args );

        while( $my_query->have_posts() ) {
            $my_query->the_post();
        ?>
            <div class="large-4 medium-4 small-12 columns img-wrap"> <a rel="external" href="<? the_permalink()?>">
                <?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') ); ?>
                <img src="<?php echo $url ?>" />
                <div class="story-title-sub">
                    <h2>
                        <?php the_title(); ?>
                    </h2>
                </div>
            </div>
            <?php }
        }
        $post = $orig_post;
        wp_reset_query();
        ?>
        </div>
    </div>
</section>

How to Display Related Posts in WordPress, In this article we will show you how you can display related posts in I was looking for a way to show related posts based on all tags and not� This template tag displays a link to the tag or tags a post belongs to. If no tags are associated with the current entry, nothing is displayed. This tag should be used within The Loop .

You can try this code for getting posts that are related by Tag

<?php // related posts based on first tag of current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {

    echo '<h3>Related Posts</h3>';

    $first_tag = $tags[0]->term_id;
    $args = array(
            'tag__in' => array($first_tag),
            'post__not_in' => array($post->ID),
            'showposts' => 7, // how many posts?
            'caller_get_posts' => 1
            );

    $my_query = new WP_Query($args);
    if ($my_query->have_posts()) { ?>

        <ul>

        <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>

        <?php endwhile; ?>

        </ul>

    <?php } ?>
<?php } ?>

Code to show related posts based on tags, Hi, is there a code available (to place in a hook) to show related posts based on tags? For example: If this post has the tag “trademark” 3 related� Added display_posts_shortcode_no_results filter for displaying content if there’s no posts matching current query. Add support for multiple post types. [display-posts post_type=”page, post”] Version 1.7. Added id argument to specify specific post IDs

You can try this process getting posts that are related by Tag:

<?php
$args = array(
   'posts_per_page' => 3, 
   'post__not_in'   => array( get_the_ID() ), 
   'orderby' => 'count',
);

$cats = wp_get_post_tags( get_the_ID(), 'tag' ); 
$cats_ids = array();  
foreach( $cats as $wpex_related_cat ) {
   $cats_ids[] = $wpex_related_cat->term_id; 
}
if ( ! empty( $cats_ids ) ) {
   $args['tag__in'] = $cats_ids;
}
$wpex_query = new wp_query( $args );
foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>

   <a href="<?php the_permalink(); ?>"><li><?php the_title(); ?></li></a>
    enter code here
<?php
endforeach;
wp_reset_postdata();
?>

How to display related posts from same category?, Answer re-written based on WP_Query() : $related = new This answer makes sure that related posts are ordered by how many tags match. For example if an� It’s easy to use, gives you multiple ways to display related posts, and the output looks great. The main downside is that it offers no control over which posts are displayed in your related posts box. Related Posts for WordPress by Bibblio (FREE/$19-plus) Bibblio is a related content service that was designed to increase your website traffic

related posts by tags only, I have activated tags for pages in my wp installation. I'm trying to get this plugin to show related items from the same category, based on tags only (if they've a tag� The display property specifies the display behavior (the type of rendering box) of an element. In HTML, the default display property value is taken from the HTML specifications or from the browser/user default style sheet. The default value in XML is inline, including SVG elements.

Get Related Posts by Tag if Tag is Empty Get Posts by Category , I'm using Ajax Load More, and I'm trying to get related posts by tag. Which works: $terms = wp_get_post_tags($post->ID); // get current categories $term_array� The related_blog_posts HubL tag can be used to create dynamic and related blog post listing based on a variety of parameters. It allows for generating listings of posts across blogs, with the ability to filter by tags, authors, post paths and publish dates.

Display Related Posts by Category, As a result, returning a handful of related posts from the same category is a strong alternative to tag-based relational posts. What's more, implementing category-� What are “conditional tags”? The conditional tags of WooCommerce and WordPress can be used in your template files to change what content is displayed based on what conditions the page matches. For example, you may want to display a snippet of text above the shop page. With the is_shop() conditional tag, you can. Because WooCommerce uses custom post …

Comments
  • I edited the above to the code i used on my site, it looks like the same script and it works on my site. Looks like the only real diffrence is you are calling the post type. Take a look and maybe you can find the answer in the above
  • Yeah that's the same code I was using. It calls all the relating tags. I've tried many variations in the $args = array( section. Hmm. Puzzling.