1

Short version: I am wondering if the default WP loop (for example in a rather simple index.php) is supposed to return custom posts belonging to a custom taxonomy when the URL is something like https://example.com/my_cpt_slug/my_taxonomy_term, or if I always need to create a template with a custom query in a situation like that?

The details: I created a custom post type and a custom taxonomy (in a custom theme), using the Pods plugin. Let’s call the CPT picture and the taxonomy motive for the following example. I assigned the motive taxonomy exclusively to the picture CPT.

The CPT works well – I created a php template (single-picture.php) for its single pages, in which I used the WP function the_taxonomies(). This displays the name/s of the current taxonomy term/s of the post, linked to their archive pages (actually I only have one term per post, so it’s only one link). BTW: I am not even sure if "term" is the right word here – what I mean is something like the category name, but applied to taxonomies.

Now let’s say the taxonomy term is "landscape". So that link calls an URL like https://www.example.com/motive/landscape when clicked. Since the motive taxonomy is only used for the picture CPT, I would expect all picture custom posts which have the landscape term assigned to them to be displayed in a list, like regular posts on a blog page. However, the resulting page (which for now uses the index.php template) displays no posts, but instead the message which is included in the else part of the WP loop!

Now, I can create a taxonomy-motive.php template and use a custom query in it, querying the desired CPT and taxonomy name, which works. But I would expect that also the standard WP loop/query in the index.php file returns a list of those posts?

Did I oversee anything or will a regular WP loop really not display any posts in this situation?

P.S.: One additional detail – I don’t know if it makes any difference: My WP site uses a subdirectory of a domain as its home URL, like https://www.example.com/mysite. So the above mentioned link is actually https://www.example.com/mysite/motive/landscape.

  • Could you include the code you're using to register the post type and taxonomy? – Jacob Peattie Dec 6 '19 at 0:06
  • @JacobPeattie As I wrote, I used the Pods plugin to create both, which does the registering. According to the Pods people, "The settings for CPT and taxonomies within Pods are the actual WordPress core settings for registering CPT and taxonomies. Pods merely registers them." – Johannes Dec 6 '19 at 0:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.