Note that there are some explanatory texts on larger screens.

plurals
  1. POWordPress Related Post Error
    primarykey
    data
    text
    <p>I did a search not only on Google but other places, including here and cannot find anything to help with this issue.</p> <p>Here is the problem. I have a related posts snippet based on tags instead of categories, that I use in WordPress themes and I have been using it for quite some time and it works really well. Here is is:</p> <pre><code> $tags = wp_get_post_tags($post-&gt;ID); $tagIDs = array(); if ($tags) { $tagcount = count($tags); for ($i = 0; $i &lt; $tagcount; $i++) { $tagIDs[$i] = $tags[$i]-&gt;term_id; } $args=array( 'tag__in' =&gt; $tagIDs, 'post__not_in' =&gt; array($post-&gt;ID), 'showposts'=&gt;mytheme_option( 'related_count' ), 'ignore_sticky_posts'=&gt;1 ); $my_query = new WP_Query($args); if( $my_query-&gt;have_posts() ) { echo '&lt;h4&gt;'. __('Other Posts You May Be Interested In', "themename"). ':&lt;/h4&gt;&lt;ul&gt;'; while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt; &lt;li class="imglink"&gt; &lt;!-- post loop stuff goes here --&gt; &lt;/li&gt; &lt;?php endwhile; echo '&lt;/ul&gt;'; } else { echo '&lt;h4&gt;'. __('Other Posts You May Be Interested In', "themename"). ':&lt;/h4&gt; '. __('&lt;p&gt;There are no related posts at this time.&lt;/p&gt;', "themename"). ''; } } $post = $original_post; wp_reset_query(); </code></pre> <p>Like I said it works really well. If posts have the same tag, then this shows:</p> <blockquote> <p>Other Posts you May Be Interested In: posts with the same tag get displayed</p> </blockquote> <p>BUT here is the problem: If a single post is given a tag and no other posts have that same tag, this is what shows:</p> <blockquote> <p>Other posts you may be interested in: There are no related posts at this time.</p> </blockquote> <p>Now if a post is not assigned a tag, absolutely nothing shows. The div where related posts are supposed to display is empty but it should say there are no related posts.</p> <p>I have looked for a solution and tried many different things to get this corrected but I can't seem to get my head around it. Can someone assist me in getting:</p> <blockquote> <p>Other posts you may be interested in: There are no related posts at this time.</p> </blockquote> <p>to display if a post has no tag. Any help is greatly appreciated and thank you very much in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload