Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe the problems comes from the conditional towards the top of the function:</p> <pre><code>$tags = wp_get_post_tags($post-&gt;ID); $tagIDs = array(); if ($tags) { # All of your code is in this conditional, # if there are no tags, nothing will happen } </code></pre> <p>If no tags are found for the post, it skips all your code and doesn't render anything. The else statement at the bottom of your code is only executed if there are tags for the current post, but no other posts contain that tag.</p> <p><strong>Edit</strong> with example as requested - you need to have 2 else conditions which echo out the no posts content, one for if there are no tags and one for if there are tags but posts were not found:</p> <pre><code>$tags = wp_get_post_tags($post-&gt;ID); $tagIDs = array(); if ( count( $tags ) &gt; 0) { // setup $tagIDs and perform query... if( $my_query-&gt;have_posts() ) { // Echo out posts. } 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"). ''; } } 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"). ''; } </code></pre> <p>That should do it. I would maybe suggest wrapping the content into a function, however. Then you could just echo out the no post content at the end of the function, and 'return' if posts were found. Then you wouldn't be repeating yourself.</p>
    singulars
    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.
 

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