Created
November 21, 2023 18:06
-
-
Save Rupashdas/0f904c80aa28187f57edcdb5aa1e7c7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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