It fals under several categories ( example - featured) . I was trying to create a category archive, that excludes the referrer hotel from the list being displayed.
Is it possible?
Thanks.
Ok - you mean you want to exclude the post from the taxonomy/category archvie from where user clicked on the archive link. Lets say you are on post A and you click on the taxonomy/category archive link on that post and now on taxonomy/category archvie you want to exlcude post A - correct?
Well - you should try to use the native WordPress pre_get_post hook in order to exclude the referrer post.
For example:
function exclude_referrer_post_from_tax_archive( $query ) {
// Only modify the main query on taxonomy archives
if ( !is_admin() && $query->is_main_query() && is_tax() ) {
// Get the referring URL
$referer = wp_get_referer();
if ( $referer ) {
// Try to extract the post ID from the referer URL
$referer_post_id = url_to_postid( $referer );
if ( $referer_post_id ) {
// Exclude the referring post from the query
$query->set( 'post__not_in', array( $referer_post_id ) );
}
}
}
}
add_action( 'pre_get_posts', 'exclude_referrer_post_from_tax_archive',99,1);
- you can adjust the code as required for your taxonomy archive.