On a single post page I have the following code after my loop:
<?php previous_post_link('« %link') ?> |
<?php next_post_link(' %link »') ?>
For some reason, it is not retrieving the next items in the category, it is only finding the next item in that tag grouping. The category is “rentals” (for example) and the tag is “neighborhood x” (for example). But the links are limited, only showing for “neighborhood x” (tag) and not for “rentals” (category).
Is there any way to make the navigation links use everything in the category instead of the tag?
Defaults
First, you don’t have to put
'« %link'
in, as this is already the default value.WPDB Query
Your “Problem” is, that the underlying funtion
adjacent_post_link()
usesget_adjacent_post()
if it’s not querying an attachment.This then builds the following
JOIN
part for the query:Filter the query, before executing it:
Here’s the filter description from the core function:
That means, that you can build the following plugin – IF you set the
$in_same_cat
argument toTRUE
(Hint: This is the 3rd argument fornext_/previous_post_link()
).