内部を理解する
隣接する(次/前)投稿の「ソート」順序は、実際にはソート「順序」ではありません。リクエスト/ページごとに個別のクエリですが、クエリをpost_date-または現在表示されているオブジェクトとして階層的な投稿がある場合は投稿の親で並べ替えます。
の内部next_post_link()を見ると、基本的にのAPIラッパーであることがわかりますadjacent_post_link()。後の関数は、次または前の投稿リンクを取得するように設定されget_adjacent_post()た$previous引数/フラグで内部的に呼び出しますbool(true|false)。
フィルタリングするもの
さらに深く掘り下げた後、get_adjacent_post() ソースリンクにはその出力(クエリ結果)のためのいくつかの素晴らしいフィルターがあることがわかります:(フィルター名/引数)
- "get_{$adjacent}_post_join"
 - $join
// Only if `$in_same_cat`
// or: ! empty( $excluded_categories` 
// and then: 
// " INNER JOIN $wpdb->term_relationships AS tr 
//     ON p.ID = tr.object_id 
// INNER JOIN $wpdb->term_taxonomy tt 
//     ON tr.term_taxonomy_id = tt.term_taxonomy_id"; 
// and if $in_same_cat then it APPENDS: 
// " AND tt.taxonomy = 'category' 
// AND tt.term_id IN (" . implode(',', $cat_array) . ")";
$in_same_cat
$excluded_categories
 
- "get_{$adjacent}_post_where"
 - $wpdb->prepare(
      // $op = $previous ? '<' : '>'; | $current_post_date
       "WHERE p.post_date $op %s "
      // $post->post_type
      ."AND p.post_type = %s "
      // $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' 
      // AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')'; 
      // OR empty string if $in_same_cat || ! empty( $excluded_categories
      ."AND p.post_status = 'publish' $posts_in_ex_cats_sql "
    ",
    $current_post_date,
    $post->post_type
)
$in_same_cat
$excluded_categories
 
- "get_{$adjacent}_post_sort"
 - "ORDER BY p.post_date $order LIMIT 1"`
 
だから、あなたはそれでたくさんすることができます。それは、WHERE句、JOINおよびedテーブルとORDER BYステートメントのフィルタリングから始まります。
結果は現在のリクエストのメモリにキャッシュされるため、単一のページでその関数を複数回呼び出しても、クエリは追加されません。
自動クエリ構築
以下のよう@StephenHarrisは:コメントで指摘し、SQLクエリを構築するときに便利になるかもしれないコア機能がありますget_meta_sql()例- コーデックスでは。基本的に、この関数はで使用されるメタSQLステートメントを作成するために使用されWP_Queryますが、この場合(または他の場合)でも使用できます。そこに投げる引数は配列であり、に追加されるものとまったく同じですWP_Query。
$meta_sql = get_meta_sql(
    $meta_query,
    'post',
    $wpdb->posts,
    'ID'
);
戻り値は配列です:
$sql => (array) 'join' => array(),
        (array) 'where' => array()
だから、使用することができます$sql['join']し、$sql['where']あなたのコールバックインチ
留意すべき依存関係
あなたの場合、最も簡単なのは、小さな(mu)プラグインまたはテーマのfunctions.phpファイルでインターセプトし、$adjacent = $previous ? 'previous' : 'next';変数と変数に応じて変更すること$order = $previous ? 'DESC' : 'ASC';です。
実際のフィルター名
したがって、フィルター名は次のとおりです。
- get_previous_post_join、- get_next_post_join
- get_previous_post_where、- get_next_post_where
- get_previous_post_sort、- get_next_post_sort
プラグインとしてまとめられました
...また、フィルターコールバックは(たとえば)次のようになります。
<?php
/** Plugin Name: (#73190) Alter adjacent post link sort order */
function wpse73190_adjacent_post_sort( $orderby )
{
    return "ORDER BY p.menu_order DESC LIMIT 1";
}
add_filter( 'get_previous_post_sort', 'wpse73190_adjacent_post_sort' );
add_filter( 'get_next_post_sort', 'wpse73190_adjacent_post_sort' );