In wordpress, I am trying to get current id of a row and a next id of upcoming row.

Example database:

    -----------------------------
    |   id  |   book  | orderby |
    -----------------------------
    |    3  |    b    |     1   |
    -----------------------------
    |    1  |    f    |     2   |
    -----------------------------
    |    2  |    g    |     3   |
    -----------------------------

code:

$entries = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."_books" ORDER BY orderby ASC );
foreach ( $entries as $print ){
    $prev = //on second row this would be 3
    $current = $print->id  //on second row this would be 1
    $next =  //on second row this would be 2
}

I think in none WordPress way you would just increase or decrease array key in loop. It is prolly simple fix.

Read more here: In wordpress foreach loop, return current row id and next/prev row id


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: