Creating next previous buttons for items in a taxonomy

I have created a taxonomy for gallery posts called clients I want to have next previous buttons that give me the next gallery for the same client.
tried just adding {{dc:post:permalink post=“next”}}

Then I tried adding a looper provider of current post and a filter of taxonomy clients and then using the same and it is still just cycling through all the galleries

Hi @wicara,

Unfortunately, that is not possible right this moment.

Thanks

can I use any filters on the next eg can I get any gallery in a category ? so it only gets the next link for a post that is in the specified category?

Hi @wicara,

You can use any hook or filter that helps you, but please remember that custom coding is beyond the scope of Theme Support.

Thanks

So, there is no way to perform a filtered next-link group with loopers in the current build ? I was thinking I may be able to do it via a query string or query builder or is the dynamic text specific for {{dc:post:permalink post=“next”}}

For the punters;

The {{dc:post:permalink post="next"}} tag by default will follow the standard WordPress post order, which doesn’t include the custom filters like the specific ‘client’ (custom taxonomy I created) taxonomy term (‘xyz’) in the query string. Essentially, it’s just getting the next post in sequence, not the next post that matches your specific query criteria. It doesn’t inherently respect the specific filters or constraints of a custom query.

// 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

Hi @wicara,

Glad that you shared the solution here.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.