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

質問編集履歴

3

一部訂正しました。

2019/01/26 03:15

投稿

narutonaruti
narutonaruti

スコア15

title CHANGED
File without changes
body CHANGED
@@ -40,9 +40,9 @@
40
40
  if ( is_admin() || ! $query->is_main_query() ) {
41
41
  return;
42
42
  }
43
- if ( $query->is_page( 'week' ) ) {
43
+ if ( $query->is_page( 'week' ) ) { // weekはslugです
44
44
  $query->set( 'posts_per_page', 20 );
45
- $query->set( 'post_type', array( 'monday' ) );
45
+ $query->set( 'post_type', array( 'monday' ) ); // これがあると404
46
46
  $query->set( 'author', get_current_user_id() );
47
47
  return;
48
48
  }

2

一部訂正しました。

2019/01/26 03:15

投稿

narutonaruti
narutonaruti

スコア15

title CHANGED
File without changes
body CHANGED
@@ -6,11 +6,12 @@
6
6
  [こちらのサイト](https://techmemo.biz/wordpress/pre_get_posts/)を参考に下記のソースコードを書き、しかし問題が発生中です。
7
7
 
8
8
  ### 発生している問題・エラーメッセージ
9
+ 「カスタム投稿タイプ(monday)」の一覧を表示するために、
9
10
  functions.phpに
10
11
  ``$query->set( 'post_type', array( 'monday' ) ); ``
11
- があると404になります。
12
+ を書くと404になります。
12
13
 
13
- またはこれを消せば404には行かなくなりますが、でも「固定ページ(page-week.php)」の``<h3><?php echo get_the_title(); ?></h3>``が表示するのは、「固定ページ(page-week.php)」のタイトルであって、「カスタム投稿タイプ(monday)」のタイトルではありません。
14
+ またはこれを消せば404には行かなくなりますが、でもその場合、「固定ページ(page-week.php)」の``<h3><?php echo get_the_title(); ?></h3>``が表示するのは、「固定ページ(page-week.php)」のタイトルであって、「カスタム投稿タイプ(monday)」のタイトルではありません。
14
15
 
15
16
  一体なぜ上のような問題が発生し、どうしたらうまくいくのでしょうか?
16
17
  ご意見、ご回答、よろしくお願いいたします。

1

一部訂正しました。

2019/01/26 03:13

投稿

narutonaruti
narutonaruti

スコア15

title CHANGED
File without changes
body CHANGED
@@ -3,30 +3,28 @@
3
3
  「固定ページ(page-week.php)」に、
4
4
  「カスタム投稿タイプ(monday)」の一覧を表示するコードを完成させたいです。
5
5
 
6
+ [こちらのサイト](https://techmemo.biz/wordpress/pre_get_posts/)を参考に下記のソースコードを書き、しかし問題が発生中です。
7
+
6
8
  ### 発生している問題・エラーメッセージ
9
+ functions.phpに
7
- [こちらのサイト](https://techmemo.biz/wordpress/pre_get_posts/)を参考に下記を書いてみました。
10
+ ``$query->set( 'post_type', array( 'monday' ) ); ``
11
+ があると404になります。
8
12
 
9
- ですが、下記のpage-week.phpのループに書いた
10
- ``<h3><?php echo get_the_title(); ?></h3>``
13
+ またはこれを消せば404には行かなくなりますが、でも「固定ページ(page-week.php)」の``<h3><?php echo get_the_title(); ?></h3>``が表示するのは、「固定ページ(page-week.php)」のタイトルであって、「カスタム投稿タイプ(monday)」のタイトルではありません。
11
- が表示するのは、
12
- 「カスタム投稿タイプ(monday)」のタイトルではなくて、
13
- 「固定ページ(page-week.php)」のタイトルです。
14
14
 
15
- 後に記載しているように、functions.phpで
16
- ``$query->set( 'post_type', array( 'monday' ) );``と指定しているのに、
17
- 「カスタム投稿タイプ(monday)」は1つも表示されないんです。
18
-
19
- 一体なぜうまくいかず、どうしたらいのでしょうか?
15
+ 一体なぜ上のよな問題が発生し、どうしたらうまくのでしょうか?
20
- よろしくお願いいたします。
16
+ ご意見、ご回答、よろしくお願いいたします。
21
17
  ### 該当のソースコード
22
- ↓記事一覧出力するループ(page-week.php)
18
+ ↓記事一覧出力するループ(page-week.php)
23
19
  ```php
24
20
  <?php
25
21
  /**
26
22
  * Template Name: page-week
27
23
  **/
28
24
  ?>
25
+
29
26
  <h2>「カスタム投稿タイプ(monday)」の記事一覧を出力したい<h2>
27
+
30
28
  <?php if (have_posts()): ?>
31
29
  <?php while (have_posts()) : the_post(); ?>
32
30
  <h3><?php echo get_the_title(); ?></h3>