• Medesko

    (@medesko)


    Hello!
    I have a post in two categories, A and B.
    I check by term and i m in categories A i want to get the previous post in for categories not for two.

    Thank for help

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Use the filter ‘get_previous_post_where’. Your callback is passed the WHERE clause for the query. Part of it will contain AND tt.term_id IN (4) where the ‘4’ will be the ID of the current term. Modify this string to contain both IDs of the category terms you want. If the IDs you want are 4 and 7, the string should be changed to AND tt.term_id IN (4,7)

    The filter ‘get_next_post_where’ works for going the other direction.

    Thread Starter Medesko

    (@medesko)

    Hi ,
    Thanks for your explain.

    I followed your explanation and work perfectly! here is my code !

    Thank for code quality checking!
    `
    function custom_get_xxx_post_where($whereSql) {
    global $custom_get_xxx_post_where;
    if(isset($custom_get_xxx_post_where) === true AND $custom_get_xxx_post_where === true) {
    if($_SESSION[‘cat_name’] == ‘dsi’) {
    $whereSql .= ‘ AND tt.term_id = 2 ‘;
    } else if($_SESSION[‘cat_name’] == ‘metiers’) {
    $whereSql .= ‘ AND tt.term_id = 3 ‘;
    }
    }
    return $whereSql;
    };
    add_filter(‘get_previous_post_where’, ‘custom_get_xxx_post_where’);
    add_filter(‘get_next_post_where’, ‘custom_get_xxx_post_where’);

    <?php
    $custom_get_xxx_post_where = true;
    previous_post_link(‘<div class=”dossier-control hidden-sm hidden-xs”> %link</div>’, ‘Prev’, true);
    next_post_link(‘<div class=”dossier-control hidden-sm hidden-xs”>%link</div>’, ‘Next’, true);
    $custom_get_xxx_post_where = false;
    ?>
    `

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_previous_post in two categorie’ is closed to new replies.