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

質問編集履歴

1

修正

2021/04/22 16:51

投稿

pocoto
pocoto

スコア5

title CHANGED
File without changes
body CHANGED
@@ -30,4 +30,23 @@
30
30
  ");
31
31
  return $number;
32
32
  }
33
+ ```
34
+ カテゴリーの方法もあったのですが動作せず今回はカスタム投稿を利用しているので
35
+ タクソノミーとタームを絞り込む必要があるのでしょうか・・
36
+ ```
37
+ function getPostThNumber() {
38
+ global $wpdb, $post;
39
+ $categoryID = get_the_terms($post->ID)[0]->term_id;
40
+
41
+ $number = $wpdb->get_var("
42
+ SELECT COUNT(*)
43
+ FROM $wpdb->posts INNER JOIN $wpdb->term_relationships ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
44
+ WHERE post_status = 'publish'
45
+ AND post_type = 'post'
46
+ AND term_taxonomy_id = $categoryID
47
+ AND post_date <= '$post->post_date'
48
+ ");
49
+
50
+ return $number;
51
+ }
33
52
  ```