Like WP get_adjacent_post
function gives the next and previous post data based on the parameters i want to get the next/previous category data is there any WP
built in function which does the right job or i have to write a custom query for that.
// Next/previous post example
$in_same_cat = false;
$excluded_categories = '';
$previous = true;
$previous_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
i want next category by category slug
or by category id
Any help would be appreciated
No.
No. Use get_terms(). Here is an example.
Add the
wpse_99513_adjacent_category
class to the functions.php theme file and call it like this:— ‘category’ is the taxonomy,
— ‘id’ is the field to order the database query by and
— false shows empty categories.
To get the next taxonomy use this:
— $category is the id of the category you are checking,
— $next_category is set to false if there is an error and the next ID otherwise.
Previous works the same way:
— $category is the id of the category you are checking,
— $previous_category is set to false if there is an error and the previous ID otherwise.
For slugs which skips empty categories use:
This is what I came up with. Maybe not the best but works 🙂
Assuming we are on a custom taxonomy category page, and we want to go to the next
I am not sure about bulit-in functions in WordPress but you can
Get Next and Previous Pages and than their category using next and previous post ID.
This is what i came up with a custom query solution hope it help others i wrote a custom function for this it works for all post type categories (post,custom post types)
Little update based on Akmur answer
Place this function in your functions.php:
And this as your prev/next links (function parameters are examples):