the-seo-framework
the-seo-framework copied to clipboard
Make archive exclusions work for adjacent post links.
From nuwif's idea:
Make archive exclusions work on next/prev links.
I want to make this optional because although the next/prev links are determined via archive lookups, they aren't of an archive themselves.
- On by default for new/reset sites.
- Off by default for old sites.
Here's a quick filter to incorporate it yourself. Note that this will not be how it will work eventually.
add_filter( 'get_previous_post_where', 'my_tsf_exclude_posts_from_adjacent_links_where' );
add_filter( 'get_next_post_where', 'my_tsf_exclude_posts_from_adjacent_links_where' );
/**
* Exclude posts from next/prev adjacent links.
*
* @param string $where The where-clause.
* @return string
*/
function my_tsf_exclude_posts_from_adjacent_links_where( $where ) {
if ( ! function_exists( 'tsf' ) ) return $where;
$excluded = tsf()->query()->exclusion()->get_excluded_ids_from_cache()['archive'];
if ( ! $excluded ) return $where;
$where .= " AND p.ID NOT IN (" . implode( ',', array_map( 'intval', $excluded ) ) . ')';
return $where;
}
To learn where to place a filter, see https://tsf.fyi/kb/using-filters/#where.
Thanks a lot, Sybre! I am so happy that you decided to implement this option. Thank you for your quick filter, it works perfectly! (Your support is amazing by the way.)