// Add this code to your theme's functions.php file
function get_next_client_post_link_loop() {
global $post;
$next_post = get_adjacent_post(true, '', false, 'client');
// If there's no next post, get the first one
if (!$next_post) {
$args = array(
'post_type' => $post->post_type,
'posts_per_page' => 1,
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'client',
'field' => 'term_id',
'terms' => wp_get_post_terms($post->ID, 'client', array('fields' => 'ids')),
),
),
);
$first_post = new WP_Query($args);
if ($first_post->have_posts()) {
$first_post->the_post();
$next_post = $post;
wp_reset_postdata();
}
}
return ($next_post) ? get_permalink($next_post->ID) : '';
}
function get_previous_client_post_link_loop() {
global $post;
$previous_post = get_adjacent_post(true, '', true, 'client');
// If there's no previous post, get the last one
if (!$previous_post) {
$args = array(
'post_type' => $post->post_type,
'posts_per_page' => 1,
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'client',
'field' => 'term_id',
'terms' => wp_get_post_terms($post->ID, 'client', array('fields' => 'ids')),
),
),
);
$last_post = new WP_Query($args);
if ($last_post->have_posts()) {
$last_post->the_post();
$previous_post = $post;
wp_reset_postdata();
}
}
return ($previous_post) ? get_permalink($previous_post->ID) : '';
}
// Create shortcodes for these functions
function register_client_post_link_loop_shortcodes() {
add_shortcode('next_client_link_loop', 'get_next_client_post_link_loop');
add_shortcode('previous_client_link_loop', 'get_previous_client_post_link_loop');
}
add_action('init', 'register_client_post_link_loop_shortcodes');
For those who have a similar issue use code at your own risk