get_adjacent_post

Sponsored Link

隣接する投稿を取得します。

次または前のポストのどちらでもかまいません。

Sponsored Link

Retrieve adjacent post.

Can either be next or previous post.

get_adjacent_postのファンクションタグ使用方法

<?php get_adjacent_post( $in_same_cat, $excluded_categories, $previous ) ?>

get_adjacent_postのパラメーター

$in_same_cat

(boolean) (optional)同じカテゴリーに投稿すべきかどうか。
デフォルト:false

(boolean) (optional) Whether post should be in same category.
Default: false

$excluded_categories

(string) (optional)カテゴリーIDを除外します。
Default: ”

(string) (optional) Excluded categories IDs.
Default: ”

$previous

(boolean) (optional) 前の記事を取得するかどうか。
Default: true

(boolean) (optional) Whether to retrieve previous post.
Default: true

戻り値

  • 投稿オブジェクト成功した場合。
  • グローバル$postが設定されていない場合はnullを返します。
  • 対応するポストが存在しない場合、空の文字列。
  • Post object if successful.
  • Null if global $post is not set.
  • Empty string if no corresponding post exists.

注釈

  • Uses global: (object) $post
  • Uses global: (object) $wpdb

フィルター

$adjacentは、”前”または”横”のどちらかです。

$adjacent is either ‘previous’ or ‘next’.

  • “get_{$adjacent}_post_join”:
    $join, $in_same_cat, $excluded_categories
  • “get_{$adjacent}_post_where”:
    $wpdb->prepare(“WHERE p.post_date $op %s AND p.post_type = %s 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”

変更ログ

Since: 2.5.0

ソースファイル

get_adjacent_post()は、wp-includes/link-template.php内に位置しています。

get_adjacent_post() is located in wp-includes/link-template.php.

Sponsored Link