ワードプレス(WordPress)get postsのパラメーター説明
パラメーターとデフォルトの値
<?php $args = array(
‘posts_per_page’ => 5,
‘offset’ => 0,
‘category’ => ”,
‘category_name’ => ”,
‘orderby’ => ‘date’,
‘order’ => ‘DESC’,
‘include’ => ”,
‘exclude’ => ”,
‘meta_key’ => ”,
‘meta_value’ => ”,
‘post_type’ => ‘post’,
‘post_mime_type’ => ”,
‘post_parent’ => ”,
‘author’ => ”,
‘post_status’ => ‘publish’,
‘suppress_filters’ => true
);
$posts_array = get_posts( $args ); ?>
パラメーター | 説明 |
---|---|
posts_per_page | 表示する最大投稿数 |
offset | 先頭から表示しない記事の数 |
category | カテゴリIDを指定 |
category_name | カテゴリーのスラッグを指定 |
orderby | 並び順の下記から基準を指定 date:日付 none:順序無し ID:投稿ID author:作成者 title:タイトル modified:更新日 parent:親ページのID rand:ランダム comment_count:コメント数 menu_order:ページ順序 meta_value:クエリに ‘meta_key=keyname’ がある場合のみ有効。 meta_value_num:メタフィールドの値。 |
order | ASC(昇順)、DESC(降順)かを指定 |
include | 投稿IDを指定 |
meta_key | カスタムフィールドを指定 |
meta_value | 上記のカスタムフィールドの値を指定 |
post_type | 投稿のタイプを指定 |
post_mime_type | MIMEタイプの指定 |
post_parent | 親ページのIDを指定 |
author | 作成者を指定 |
post_status | 投稿ステータスを指定 publish:公開済 private:非公開 |
suppress_filters | フィルタリングの有効、無効 フィルター処理を行わない場合はtrue、フィルター処理を行う場合はfalseを指定 |