Skip to content

Instantly share code, notes, and snippets.

@Rupashdas
Created November 21, 2023 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rupashdas/0f904c80aa28187f57edcdb5aa1e7c7c to your computer and use it in GitHub Desktop.
Save Rupashdas/0f904c80aa28187f57edcdb5aa1e7c7c to your computer and use it in GitHub Desktop.
<?php
function rl_cold_next_post_id( $post_id, $post_type ) {
global $post;
$oldGlobal = $post;
$post = get_post( $post_id );
$previous_post = get_previous_post();
$post = $oldGlobal;
if($previous_post == ""){
return rl_cold_new_post_id($post_type);
}
return $previous_post->ID;
}
function rl_cold_new_post_id($post_type) {
$rl_cold_args = array(
'post_type' => $post_type,
'post_status' => 'publish',
'posts_per_page' => 1,
'order' => 'DESC',
);
$rl_cold_team_post = new WP_Query($rl_cold_args);
while($rl_cold_team_post->have_posts()){
$rl_cold_team_post->the_post();
return get_the_ID();
}
wp_reset_query();
}
function rl_cold_previous_post_id( $post_id, $post_type) {
global $post;
$oldGlobal = $post;
$post = get_post( $post_id );
$next_post = get_next_post();
$post = $oldGlobal;
if($next_post == ""){
return rl_cold_old_post_id($post_type);
}
return $next_post->ID;
}
function rl_cold_old_post_id($post_type) {
$rl_cold_args = array(
'post_type' => $post_type,
'post_status' => 'publish',
'posts_per_page' => 1,
'order' => 'ASC',
);
$rl_cold_post_post = new WP_Query($rl_cold_args);
while($rl_cold_post_post->have_posts()){
$rl_cold_post_post->the_post();
return get_the_ID();
}
wp_reset_query();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment