WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So, i got a custom post type applied to different posts and also a page. When i display this page, it shows some content (text), and at the bottom a link to get the list of the products related to this page (thanks to the CPT also applied to the page).

The link is called like this:

echo get_the_term_list( $post->ID, 'prod-cate', 'Products of the cateogry: ', ', ', '.' ); 

When i hit this link, it displays an archives page with the products but also the page i'm comming from.

The question is, how not to display this page in the archives results?

share|improve this question

Call the link with a query argument in which you pass the current post ID.

If get_the_term_list returns a url address (the link href) you would need to append a argument to it. Then, on the archive page exclude that post ID before the loop, using something like:

  query_posts(array('post__not_in' => array(intval($_GET['related_to']))));

Update: I've looked up get_the_term_list and it seems to be a wp function that lists html-formatted term links. So you'll need to append your query argument before the links are built. In your functions.php file add:

function my_related_link($termlink, $term, $taxonomy){
  global $post;
  return add_query_arg('related_to', $post->ID, $termlink);

and in the template file where the link is added:

add_filter('term_link', 'my_related_link', 10, 3);
echo get_the_term_list( $post->ID, 'prod-cate', 'Products of the cateogry: ', ', ', '.' );
remove_filter('term_link', 'my_related_link');
share|improve this answer
Thanks for the help AA. It gives me a 'not found' result on the archive page. I think that something's wrong with the final url result: "nb/kajoma/?prod-categoria=magia-das-fadas"+rel%3D"tag">Magia+das+fadas</a>.&rel‌​ated_to=124<a%20href=" Fyi, 'prod-categoria' is 'prod-cate'. – kevin Jan 5 '11 at 18:38
that's because that function doesn't return URLs. I've updated my answer, use that filter to build the links. – onetrickpony Jan 5 '11 at 22:54
I've tried this new solution and the problem is that (from my point of view) it created a new query, so it just shows the 'normal' posts from the default post type (which i use as blog posts) and not from my custom post type (for products) anymore. – kevin Jan 6 '11 at 15:07
how does your loop on the archive page look like? – onetrickpony Jan 6 '11 at 15:46
if ( have_posts() ) the_post(); rewind_posts(); get_template_part( 'loop', 'archive' ); It's the basic archive page and it works fine but displays also the page that has the same taxonomy. – kevin Jan 6 '11 at 17:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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