質問するログイン新規登録

回答編集履歴

2

 

2017/09/12 01:49

投稿

退会済みユーザー
answer CHANGED
@@ -1,5 +1,5 @@
1
- ```query_posts```は推奨されてないので```WP_Query```を使いましょう。
1
+ query_postsは推奨されてないのでWP_Queryを使いましょう。
2
- ```wp_get_current_user```でログインユーザー情報を取得できます。
2
+ wp_get_current_userでログインユーザー情報を取得できます。
3
3
 
4
4
  関数リファレンス/WP Query
5
5
  [https://wpdocs.osdn.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](https://wpdocs.osdn.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)
@@ -9,4 +9,24 @@
9
9
  [https://codex.wordpress.org/wp_get_current_user](https://codex.wordpress.org/wp_get_current_user)
10
10
 
11
11
  **追記**
12
- ふと気付きましたが、提示されたコードの6行目の```<?php endif; ?>```は、このままのコードだと要りません。と言うかエラーになるはずです。
12
+ ふと気付きましたが、提示されたコードの6行目の<?php endif; ?>は、このままのコードだと要りません。と言うかエラーになるはずです。
13
+
14
+
15
+
16
+ **追記**
17
+ こんな感じで
18
+ ```
19
+ <?php
20
+ $current_user = wp_get_current_user();
21
+ $user_id = $current_user->ID;
22
+ $query = new WP_Query(
23
+ array(
24
+ 'author' => $user_id,
25
+ 'posts_per_page' => 5,
26
+ )
27
+ );
28
+ if ( $query->have_posts() ):
29
+ while ( $query->have_posts() ):
30
+ $query->the_post();
31
+ ?>
32
+ ```

1

 

2017/09/12 01:49

投稿

退会済みユーザー
answer CHANGED
@@ -6,4 +6,7 @@
6
6
 
7
7
 
8
8
  Function Reference/wp get current user
9
- [https://codex.wordpress.org/wp_get_current_user](https://codex.wordpress.org/wp_get_current_user)
9
+ [https://codex.wordpress.org/wp_get_current_user](https://codex.wordpress.org/wp_get_current_user)
10
+
11
+ **追記**
12
+ ふと気付きましたが、提示されたコードの6行目の```<?php endif; ?>```は、このままのコードだと要りません。と言うかエラーになるはずです。