How do I get tags linking to proper pages (/tag/sample-tag -> pages with that tag)

(Warning: WordPress newbie ahead...)

I have a WP site with a bunch of posts, many of which have tags associated with them. However, clicks on links to such tags -- https://example.com/tag/sample-tag) -- don't produce the pages I would expect -- a collection of teasers for posts with that tag. I just get the nothing page -- Nothing Found / It seems we can’t find what you’re looking for. Perhaps searching can help.

I've dug through the database, and it looks like the tags are set up correctly -- proper cross-pointing entries in wp_terms, wp_term_relationships, etc, and the tags from the site show up in the standard WP Tags Cloud widget. I've checked the site logs, and the requests to /tag/sample-tag or whatever are returning a 200 status code, so the underlying mechanism seems to be ok -- it's just not producing the matching pages. Down in the Permalink settings, I've tried setting the optional tag base field to tag or to nothing, but neither works. I've also tried switching from my custom theme to twentynineteen, but I get the same behavior there.

So: Any ideas? Am I misinterpreting how these links are supposed to work? Anything else? Thanks!

Topic template-tags tags templates Wordpress

Category Web


Found it: The posts I'm working with are instances of custom posts, and the default get_posts() function assumes that posts are just, well, posts. So it wasn't finding them, and was properly returning "none".

Solution: I added some code to my theme's function.php file, like so:

function set_up_theme() {
   ...other stuff
   function mytheme_pre_get_posts ()
      $query->set('post_type', 'my_custom_post_type');
   }
   add_action('pre_get_posts', 'mytheme_pre_get_posts');
}

Better ways or places to set this up are welcome, but it seems to be doing the trick.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.