Skip to content

Commit

Permalink
v 3.21.0
Browse files Browse the repository at this point in the history
New helper : Navigation for custom post types
  • Loading branch information
Darklg committed Dec 3, 2024
1 parent c9200a5 commit 869834d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions inc/theme/utilities/posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,39 @@ function wputh_update_without_revision($args = array()) {
add_action('pre_post_update', 'wp_save_post_revision');
return $update_action;
}

/* ----------------------------------------------------------
Navigation for custom post types
---------------------------------------------------------- */

function wputh_get_adjacents_posts($post_type, $post_id = false) {

if (!$post_id) {
$post_id = get_the_ID();
}

$all_posts = get_posts(array(
'post_type' => $post_type,
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'ASC',
'fields' => 'ids'
));

$current_post_key = array_search($post_id, $all_posts);

$previous_post = false;
if ($current_post_key > 0) {
$previous_post = $all_posts[$current_post_key - 1];
}

$next_post = false;
if ($current_post_key < count($all_posts) - 1) {
$next_post = $all_posts[$current_post_key + 1];
}

return array(
'prev' => $previous_post,
'next' => $next_post
);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wputheme",
"version": "3.20.0",
"version": "3.21.0",
"description": "WPUTheme",
"devDependencies": {
"gulp": "^4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Theme Name: WP Utilities Base Theme
Theme URI: https://github.com/WordPressUtilities/WPUTheme
Update URI: https://github.com/WordPressUtilities/WPUTheme
Description: A Framework WordPress Theme
Version: 3.20.0
Version: 3.21.0
Author: Darklg
Author URI: https://darklg.me/
License: GPLv2 or later
Expand Down

0 comments on commit 869834d

Please sign in to comment.