質問編集履歴

2

誤字

2021/09/07 12:05

投稿

seisei
seisei

スコア19

test CHANGED
File without changes
test CHANGED
@@ -28,41 +28,41 @@
28
28
 
29
29
  <?php
30
30
 
31
- function get_post_fields($post) {
31
+ function get_work_fields($work) {
32
32
 
33
- $post_custom = get_post_custom($post->ID);
33
+ $work_custom = get_post_custom($work->ID);
34
34
 
35
- // var_dump($post);
35
+ // var_dump($work);
36
36
 
37
- $post_fields = [
37
+ $work_fields = [
38
38
 
39
- 'id' => $post->ID,
39
+ 'id' => $work->ID,
40
40
 
41
41
  //公開日
42
42
 
43
- 'time' => date('Y.m.d', strtotime($posts->post_date)),
43
+ 'time' => date('Y.m.d', strtotime($works->post_date)),
44
44
 
45
- 'title' => $post->post_title,
45
+ 'title' => $work->post_title,
46
46
 
47
47
  ];
48
48
 
49
49
 
50
50
 
51
- return $post_fields;
51
+ return $work_fields;
52
52
 
53
53
  }
54
54
 
55
55
 
56
56
 
57
- function get_posts( $data ) {
57
+ function get_works( $data ) {
58
58
 
59
- if( $data['id']) return get_post_by_id($data);
59
+ if( $data['id']) return get_work_by_id($data);
60
60
 
61
61
 
62
62
 
63
63
  $default_args = [
64
64
 
65
- 'post_type' => 'posts',
65
+ 'post_type' => 'works',
66
66
 
67
67
  'posts_per_page' => -1,
68
68
 
@@ -74,13 +74,13 @@
74
74
 
75
75
  ];
76
76
 
77
- // $posts = new WP_Query( $default_args );
77
+ // $works = new WP_Query( $default_args );
78
78
 
79
- $posts = get_posts($default_args);
79
+ $works = get_posts($default_args);
80
80
 
81
- // var_dump($posts);
81
+ // var_dump($works);
82
82
 
83
- if ( empty( $posts ) ) {
83
+ if ( empty( $works ) ) {
84
84
 
85
85
  return null;
86
86
 
@@ -88,7 +88,7 @@
88
88
 
89
89
 
90
90
 
91
- $return_posts = array_map('get_post_fields', $posts);
91
+ $return_posts = array_map('get_work_fields', $works);
92
92
 
93
93
 
94
94
 
@@ -98,7 +98,7 @@
98
98
 
99
99
 
100
100
 
101
- function get_post_by_id( $data ) {
101
+ function get_work_by_id( $data ) {
102
102
 
103
103
  global $default_args;
104
104
 
@@ -110,7 +110,7 @@
110
110
 
111
111
  }
112
112
 
113
- $return_posts = get_post_fields($post);
113
+ $return_posts = get_work_fields($post);
114
114
 
115
115
  return $return_posts;
116
116
 
@@ -120,11 +120,11 @@
120
120
 
121
121
  add_action( 'rest_api_init', function () {
122
122
 
123
- register_rest_route( 'custom/v1', '/posts', array(
123
+ register_rest_route( 'custom/v1', '/works', array(
124
124
 
125
125
  'methods' => 'GET',
126
126
 
127
- 'callback' => 'get_posts',
127
+ 'callback' => 'get_works',
128
128
 
129
129
  ) );
130
130
 

1

誤字

2021/09/07 12:05

投稿

seisei
seisei

スコア19

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- 感じでパラメータを使用して、記事の取得数などをいじりたいです
13
+ 下記のような感じでパラメータを使用して、記事の取得数などをいじりたいです
14
14
 
15
15
  https://exapmle.com/wp-json/wp/v2/posts?page=[NUMBER]
16
16