Title: 固定ページの子ページ一覧を表示し、関連する最新投稿日時でソートした
Last modified: 2016年8月1日

---

# 固定ページの子ページ一覧を表示し、関連する最新投稿日時でソートした

 *  [yakikaze](https://ja.wordpress.org/support/users/yakikaze/)
 * (@yakikaze)
 * [14年、 3ヶ月前](https://ja.wordpress.org/support/topic/%e5%9b%ba%e5%ae%9a%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%ae%e5%ad%90%e3%83%9a%e3%83%bc%e3%82%b8%e4%b8%80%e8%a6%a7%e3%82%92%e8%a1%a8%e7%a4%ba%e3%81%97%e3%80%81%e9%96%a2%e9%80%a3%e3%81%99%e3%82%8b%e6%9c%80/)
 * お世話になります。WPもまだまだの初心者でございます。
    なんとも行き詰まってしま
   い、皆さまのお力をお借りしたく…
 * 親ページに子ページの一覧を表示し、子ページのauthorが投稿した最新のお知らせ1件
   の内容を抜粋して表示しています。
    今は子ページ一覧を取得したときのソート順にな
   っていますが、これをお知らせの最新投稿日時順にソートしたいと思っています。
 * ▼現状
    ※固定ページの作成順にソート ・固定ページA内容抜粋&最新投稿抜粋　<リンク
   →　固定ページAへ> ・固定ページB内容抜粋&最新投稿抜粋　<リンク　→　固定ページB
   へ> ・固定ページC内容抜粋&最新投稿抜粋　<リンク　→　固定ページCへ> ・ ・
 * ▼理想
    ※最新投稿の投稿順にソート ・固定ページB内容抜粋&最新投稿抜粋　<リンク　
   →　固定ページBへ> ・固定ページC内容抜粋&最新投稿抜粋　<リンク　→　固定ページC
   へ> ・固定ページA内容抜粋&最新投稿抜粋　<リンク　→　固定ページAへ> ・ ・
 * 最新投稿の一覧を元に固定ページの情報を取得しようと思いましたが、こちらも挫折し
   てしまいました…
 * 一応ソースを添付します。
 * > `
   >  <?php if ( $post->post_parent == 0 ) : ?> <?php $child_posts = new WP_Query(
   > array( ‘post_type’ => ‘page’, ‘post_parent’ => $post->child_of=36, ‘orderby’
   > =>’post_date’ ) );?> <?php if( $child_posts->have_posts() ): ?> <?php while(
   > $child_posts->have_posts()) : $child_posts->the_post(); ?> <?php $author_id
   > = $post->post_author; ?>
   > <a href=”<?php the_permalink() ?>”>
   >  <?php $shop_name =get_the_title(); ?> 
   > <!– お知らせの取得 –> <?php $counts = 1; $recent = new WP_Query(“author=$author_id&
   > showposts=$counts”); if($recent->have_posts()) : while($recent->have_posts()):
   > $recent->the_post(); ?> <?php $post_time =get_the_time(’20y.m.d(D)H:i’); ?>
   > <?php the_title(); ?> <?php echo mb_substr(get_the_excerpt(), 0, 40); ?>… <?
   > php echo $shop_name;?> – <?php echo $post_time;?> </a> <?php endwhile; else:?
   > > <?php _e(‘お知らせはありません’); ?><?php echo $shop_name;?> </a> <?php endif;?
   > > <?php endwhile; wp_reset_query(); ?> <?php endif; ?> <?php endif; ?> `
 * わかりにくい説明で申し訳ありませんが、ご教授頂ければ幸いです。

4件の返信を表示中 - 1 - 4件目 (全4件中)

 *  [Fumito MIZUNO](https://ja.wordpress.org/support/users/php-web/)
 * (@php-web)
 * [14年、 3ヶ月前](https://ja.wordpress.org/support/topic/%e5%9b%ba%e5%ae%9a%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%ae%e5%ad%90%e3%83%9a%e3%83%bc%e3%82%b8%e4%b8%80%e8%a6%a7%e3%82%92%e8%a1%a8%e7%a4%ba%e3%81%97%e3%80%81%e9%96%a2%e9%80%a3%e3%81%99%e3%82%8b%e6%9c%80/#post-150310)
 * 公式ドキュメントによると、orderby に `post_date` というオプションは無いですね。
   
   公式に記載されている、`date` か `modified` を使ってみてはいかがでしょう。 [http://wpdocs.sourceforge.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/WP_Query](http://wpdocs.sourceforge.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/WP_Query)
 * > orderby (string) – Sort retrieved posts by parameter. Defaults to ‘date’.
   >  ‘
   > none’ – No order (available with Version 2.8). ‘ID’ – Order by post id. Note
   > the captialization. ‘author’ – Order by author. ‘title’ – Order by title. ‘
   > date’ – Order by date. ‘modified’ – Order by last modified date. ‘parent’ –
   > Order by post/page parent id. ‘rand’ – Random order. ‘comment_count’ – Order
   > by number of comments (available with Version 2.9). ‘menu_order’ – Order by
   > Page Order. Used most often for Pages (Order field in the Edit Page Attributes
   > box) and for Attachments (the integer fields in the Insert / Upload Media Gallery
   > dialog), but could be used for any post type with distinct ‘menu_order’ values(
   > they all default to 0). ‘meta_value’ – Note that a ‘meta_key=keyname’ must 
   > also be present in the query. Note also that the sorting will be alphabetical
   > which is fine for strings (i.e. words), but can be unexpected for numbers (
   > e.g. 1, 3, 34, 4, 56, 6, etc, rather than 1, 3, 4, 6, 34, 56 as you might naturally
   > expect). ‘meta_value_num’ – Order by numeric meta value (available with Version
   > 2.8). Also note that a ‘meta_key=keyname’ must also be present in the query.
   > This value allows for numerical sorting as noted above in ‘meta_value’.
 *  トピック投稿者 [yakikaze](https://ja.wordpress.org/support/users/yakikaze/)
 * (@yakikaze)
 * [14年、 3ヶ月前](https://ja.wordpress.org/support/topic/%e5%9b%ba%e5%ae%9a%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%ae%e5%ad%90%e3%83%9a%e3%83%bc%e3%82%b8%e4%b8%80%e8%a6%a7%e3%82%92%e8%a1%a8%e7%a4%ba%e3%81%97%e3%80%81%e9%96%a2%e9%80%a3%e3%81%99%e3%82%8b%e6%9c%80/#post-150336)
 * ご指摘ありがとうございました！
    こちらでよくお見かけする方からの返信うれしかっ
   たです。
 * しかし、どちらも修正したのですが思い通りにはなりませんでした。
 * ソートをかけたい部分は最初に取得した子ページの作成日ではなく、次の条件で取得した「
   同じ作成者」が投稿した記事作成日でソートをしたいのです。
 * おそらく、何かに代入してソートをかけなければならないと思うのですが…さっぱり分
   からなくなっております。
 * もしご存じでしたら教えて頂ければ幸いです。
 *  [jim912](https://ja.wordpress.org/support/users/jim912/)
 * (@jim912)
 * [14年、 3ヶ月前](https://ja.wordpress.org/support/topic/%e5%9b%ba%e5%ae%9a%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%ae%e5%ad%90%e3%83%9a%e3%83%bc%e3%82%b8%e4%b8%80%e8%a6%a7%e3%82%92%e8%a1%a8%e7%a4%ba%e3%81%97%e3%80%81%e9%96%a2%e9%80%a3%e3%81%99%e3%82%8b%e6%9c%80/#post-150340)
 * yakikazeさん、こんにちは。
 * 以下のような感じで。
    1. ソート用の空の配列を定義
    2. 子ページを取得
    3. 子ページをループ
    4. 子ページの作成者の最新投稿を取得
    5. 最新投稿があれば、ソート用の配列に最新投稿の日時と子ページのIDをキー、子ページ
       と最新投稿のデータを値として格納
    6. 子ページのループ終了
    7. ソート用の配列をループし、子ページの抜粋と最新投稿の抜粋を表示
 *  トピック投稿者 [yakikaze](https://ja.wordpress.org/support/users/yakikaze/)
 * (@yakikaze)
 * [14年、 3ヶ月前](https://ja.wordpress.org/support/topic/%e5%9b%ba%e5%ae%9a%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%ae%e5%ad%90%e3%83%9a%e3%83%bc%e3%82%b8%e4%b8%80%e8%a6%a7%e3%82%92%e8%a1%a8%e7%a4%ba%e3%81%97%e3%80%81%e9%96%a2%e9%80%a3%e3%81%99%e3%82%8b%e6%9c%80/#post-150343)
 * jim912さん、はじめましてこんにちは！
 * 頂いたような感じで理想通りの表示になりそうです。
 * PHPかなり自信ないのですが、query_postsとforeachを使っていく感じになるんでしょう
   か。
 * なんとかがんばってやってみようと思います。
    ありがとうございます！

4件の返信を表示中 - 1 - 4件目 (全4件中)

 トピック「固定ページの子ページ一覧を表示し、関連する最新投稿日時でソートした」に
は新たに返信することはできません。

## タグ

 * [ソート](https://ja.wordpress.org/support/topic-tag/%e3%82%bd%e3%83%bc%e3%83%88/)
 * [別条件で](https://ja.wordpress.org/support/topic-tag/%e5%88%a5%e6%9d%a1%e4%bb%b6%e3%81%a7/)
 * [子ページ](https://ja.wordpress.org/support/topic-tag/%e5%ad%90%e3%83%9a%e3%83%bc%e3%82%b8/)

 * フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4件の返信
 * 3人の参加者
 * 最後の返信者: [yakikaze](https://ja.wordpress.org/support/users/yakikaze/)
 * 最後の活動: [14年、 3ヶ月前](https://ja.wordpress.org/support/topic/%e5%9b%ba%e5%ae%9a%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%ae%e5%ad%90%e3%83%9a%e3%83%bc%e3%82%b8%e4%b8%80%e8%a6%a7%e3%82%92%e8%a1%a8%e7%a4%ba%e3%81%97%e3%80%81%e9%96%a2%e9%80%a3%e3%81%99%e3%82%8b%e6%9c%80/#post-150343)
 * 状態: 未解決

## トピック

### 人気のトピック

### 返信がないトピック

### サポート関連ではないトピック

### 解決済みのトピック

### 未解決のトピック

### すべてのトピック
