默认值
首先,您不必
\'« %link\'
在中,因为这已经是默认值。
WPDB查询您的“问题”是,底层功能adjacent_post_link()
使用get_adjacent_post()
如果不是查询附件。
然后构建以下内容JOIN
查询部分:
INNER JOIN $wpdb->term_relationships
AS tr
ON p.ID = tr.object_id
INNER JOIN $wpdb->term_taxonomy tt
ON tr.term_taxonomy_id = tt.term_taxonomy_id
执行查询前过滤查询:以下是核心函数中的过滤器描述:
apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories )
这意味着,您可以构建以下插件-
IF 您设置了
$in_same_cat
参数到
TRUE
(提示:这是
next_/previous_post_link()
).
<?php
! defined( \'ABSPATH\' ) AND exit;
/** Plugin Name: Intercept Next/Prev Posts links query <code>JOIN</code>. */
# Alter »PREVIOUS« query
function wpse64909_prev_link_query( $join, $in_same_cat, $excluded_cats )
{
global $post;
// Example: Only for specific post types.
// $post_type = $post->post_type
// if ( ! in_array( $post_type, array( \'post\', \'page\' ) )
// return;
// alter $join - you have $in_same_cat and $excluded_cats to assist you
return $join;
}
add_filter( \'get_previous_post_join\', \'wpse64909_nextprev_link_query\', 10, 3 );
# Alter »NEXT« query
function wpse64909_next_link_query( $join, $in_same_cat, $excluded_cats )
{
global $post;
// alter $join - you have $in_same_cat and $excluded_cats to assist you
return $join;
}
add_filter( \'get_next_post_join\', \'wpse64909_nextprev_link_query\', 10, 3 );