Loop problem – Taxonomy

You’re trying to build the permalinks yourself? That looks really tricky and fragile.

Also, you’re getting a little confused trying to deal with the $loop WP_Query object. When you call $loop->the_post();, what you’re doing is populating the global variable $post with the next post in the $loop query object. So everywhere that you’re iterating over $loop->post, you could actually just write $post.

So, for example, replace this code:

<a href="' . get_bloginfo('url') . '/colecao/' . $loop->post->post_name . '"

with something that uses WordPress’s permalink functions, like

<a href="' . get_permalink( $post->ID ) . '"