🕌

WordPress|前後の詳細記事を同タームで取得する関数について

2022/08/24に公開

▼ 解決したコード ▼

// ▼ pagenation ▼
$prev = get_adjacent_post(true, "", true, "category");
$next = get_adjacent_post(true ,"", false, "category");

▼ Note ▼

get_adjacent_post(
  $in_same_term,  // bool
  $excluded_terms,  // string || array
  $previous,  // bool
  $taxonomy //string
);

□ $in_same_term
 → 同タームの前後の記事を取得するか
□ $excluded_terms
 → 除外するタームIDを指定する
  ※ 「コンマ区切りの文字列」or「配列」
□ $previous
 → 前の記事を取得するか
□ $taxonomy
 → 「$in_same_term」で有効化したタームの種類をスラッグで指定する
  ※ 初期値:"category"

▼ Reference ▼

Discussion

ログインするとコメントできます