0

I've created a website where I use Taxonomies for adding an extra category future. This feature works in the backend (admin) and is showing up correctly under the article. The problem is that the link doesn't work. If I click on the Taxonomy-link, it sends me to a 404 page.

This is the article: http://7ef.8b5.myftpupload.com/test/

You must click on 'Videoblogs' next to 'Soort blog' to see the problem. So what I want is to have an archive/collection page of all the posts what have the same taxonomy when you click on the taxonomy.

This is the code I added in the functions.php:

add_action( 'init', 'create_soortpost_taxonomy' );

function create_soortpost_taxonomy() {
register_taxonomy(
    'soortpost',
    'post',
    array(
        'label' => 'Soort Post',
        'hierarchical' => true,
        'public' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => true,
        'query_var' => true
    )
);
}

And the code for showing the output of the Taxonomy link in single.php is:

<?php
                    $terms = get_the_terms( $post->link , 'soortpost' );
                    $term_link = get_term_link( $term );
                    // Loop over each item since it's an array
                     if ( $terms != null ){
                     foreach( $terms as $term ) {

                     // Print the name method from $term which is an OBJECT

             echo '<a href="'.get_term_link($term->slug, 'soortpost').'">'.$term->name.'</a>'; 

 // Get rid of the other data stored in the object, since it's not needed
unset($term);
      } } ?>
3
  • If you came on this page from search, maybe that answer for similar question (but with custom post_type and custom taxonomy) will be useful: wordpress.stackexchange.com/questions/223216/… Oct 2 '17 at 19:02
  • Did you flush permalinks after adding the taxonomy? Jul 26 '19 at 15:06
  • a) just re-save settings>permalinks b) check whether you do have same or similar slugs with post types, if you do, you must register the taxonomies first and then the post types (e.g. /mylife for post type and /mylife/regions for taxonomy) (my suspicion is that the "subset" in slug rewrites needs to be added later, therefore this order)
    – jave.web
    May 2 '21 at 23:48
-1

It seems you do not have a template for your custom taxonomy. I do not think so single.php will be used for this purpose. Have a look on this ARTICLE.. Look at the hierarchy,,,

I think in your case you need taxonomy-soortpost.php

Taxonomy hierarchy:

  • taxonomy-{taxonomy}-{term}.php
  • taxonomy-{taxonomy}.php
  • tag-{slug}.php
  • tag-{id}.php
  • category-{slug}.php
  • category-{ID}.php
1
  • Thanks for your answer. I will give it a try. But it says when it's looking for page or archive.php, and will not find it, then it uses the index.php. But what I don't get is that a categorie page uses a same lay-out, as well for the search results. What I'm trying to say is that it's strange it can't generate a taxonomy page by itself? Sep 10 '15 at 10:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.