FYI, you original long code listing post eventually went through, it got put in the moderation queue, probably because of the long code. One of our mods eventually released it. I should have warned you about posting a lot of code. For future reference, please use pastebin.com for extended code snippets and just link to it here. I also removed redundant and superfluous posts from view to keep things orderly. Generally speaking, if a post that should have gone through (i.e. not actual spam) does not appear to go through, just wait a while, things usually sort themselves out. Either the cache refreshes or a mod releases your post from moderation. Going to moderation does not mean you did anything wrong, the posts the system finds needing further examination have no rhyme or reason to what it picks. It picks posts, mods look at it and typically release it. It just takes a while.
Anyway, back to your code. I tried to adapt it to my installation with minimal adjustments. I did find a few issues that should be addressed, but they are unrelated (I think) to getting post excerpts from tag slugs. The excerpts from tag slugs works fine AFAICT. So address these items I noticed and see if that helps any. Fixing these will at least allow you to be closer to determining the cause if it’s not fixed outright.
In the loop, in those function_exists() arguments (posted, updated, wordcount), each argument must be presented as a string: function_exists('posted'))
If there is not already a similar line on your template, add a global $post;
line first thing in the loop.
This line: <strong>tags();</strong>
is bad syntax. Make it into proper echo statements
echo '<strong>';
tags();
echo '</strong>';
In the tags() function, I got invalid index errors due to the $i value. Probably because I do not have any tag groups. I commented out any lines with $i. If these work for you, then fine. I just cannot confirm if they work correctly or not.
If there is any chance at all that there is a tag slug without a corresponding post with excerpt, you need to add this line right below the get_posts() call:
if (!$excerpt ) continue;
The tags() output was not displaying because all of the debug content ended up being illegal anchor tag attributes. Just so the output displays, I changed this line: $html .= ' title="' . $tag->name . "\n\n";
to this:
$html .= ' title="' . $tag->name . "\">link</a>\n\n";
And removed the </a>
from this line: $html .= '</a></li> '. "\n\n\t";
The above may be fine without the debug output. I only changed it to easily see the output. I queried for posts completely unrelated to the posts I added that matched tag slugs, so this should be the same situation as “bannana” being unrelated to “apples”, which in your case returned nothing. In my testing, your code, except altered as noted, returned excerpts from posts with the same tag slug, even though the tag slugs did not relate to posts in the loop. The loop posts merely had tags assigned, their slugs had nothing similar to tag slugs.
If, after making the corrections I suggested, you still have trouble getting unrelated tag->post excerpts, first double check the page’s HTML source to make sure the data is not simply hidden from view. If not that, apparently some plugin or your theme is causing unwanted interactions. Try deactivating all plugins and switching to the twentysixteen theme. Make a copy of twentysixteen’s page.php, giving it a new name. Replace the header comment with something like /* Template Name: Tag Excerpt Test */
Replace all of the loop code with your own. Place the tags() function declaration between the header comment and get_header(); ?>
Create a new WP page based on this template. View the new page. If all was done correctly, you should see a complete list as you expected, in particular the tag->post excerpts should work for all tags.
Reactivate your plugins one by one. Test your custom page after each. Once the output goes bad again, the last activated plugin is the culprit. If you activate all of your plugins and no problems recur, the problem was likely your theme. Confirm by copying your custom template to your normal theme, the reactivate your normal theme and view the new page. It should fail. If it looks good, determine why the page works and your original code does not. What’s different?
-
This reply was modified 7 years, 7 months ago by bcworkz. Reason: added missing backticks in line with tags()