1

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?

1 Answer 1

1

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:

if(isset($_GET['related_to']))
  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');
6
  • 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>.&related_to=124<a%20href=" Fyi, 'prod-categoria' is 'prod-cate'.
    – kevin
    Jan 5, 2011 at 18:38
  • that's because that function doesn't return URLs. I've updated my answer, use that filter to build the links. Jan 5, 2011 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, 2011 at 15:07
  • how does your loop on the archive page look like? Jan 6, 2011 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, 2011 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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