回答編集履歴
4
情報の追加。
test
CHANGED
@@ -139,3 +139,49 @@
|
|
139
139
|
var_dump( $array );
|
140
140
|
|
141
141
|
```
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
---
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
**追記:**
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
```PHP
|
156
|
+
|
157
|
+
$array_base = [ 187, 284 ];
|
158
|
+
|
159
|
+
$array = [];
|
160
|
+
|
161
|
+
foreach ( $array_base as $id ) {
|
162
|
+
|
163
|
+
$ids = get_post_ancestors( $id );
|
164
|
+
|
165
|
+
if ( empty( $ids ) ) continue;
|
166
|
+
|
167
|
+
$scores = [];
|
168
|
+
|
169
|
+
foreach ( $ids as $i ) {
|
170
|
+
|
171
|
+
$scores[] = get_post_meta( $i, 'score', true );
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
$array[] = [
|
176
|
+
|
177
|
+
'ids' => $ids,
|
178
|
+
|
179
|
+
'scores' => $scores
|
180
|
+
|
181
|
+
];
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
var_dump( $array );
|
186
|
+
|
187
|
+
```
|
3
情報の追加。
test
CHANGED
@@ -99,3 +99,43 @@
|
|
99
99
|
var_dump( $array );
|
100
100
|
|
101
101
|
```
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
---
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
**追記:**
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
```PHP
|
114
|
+
|
115
|
+
$array_base = array( 187, 284 );
|
116
|
+
|
117
|
+
$array = array();
|
118
|
+
|
119
|
+
foreach ( $array_base as $id ) {
|
120
|
+
|
121
|
+
$ids = get_post_ancestors( $id );
|
122
|
+
|
123
|
+
if ( empty( $ids ) ) continue;
|
124
|
+
|
125
|
+
$scores = get_post_meta( $ids[ count( $ids ) - 1 ], 'score', true );
|
126
|
+
|
127
|
+
$tmp = [
|
128
|
+
|
129
|
+
'ids' => $ids,
|
130
|
+
|
131
|
+
'scores' => $scores
|
132
|
+
|
133
|
+
];
|
134
|
+
|
135
|
+
array_push($array, $tmp);
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
var_dump( $array );
|
140
|
+
|
141
|
+
```
|
2
情報の追加。
test
CHANGED
@@ -57,3 +57,45 @@
|
|
57
57
|
【PHP: array_shift - Manual】
|
58
58
|
|
59
59
|
[http://php.net/manual/ja/function.array-shift.php](http://php.net/manual/ja/function.array-shift.php)
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
---
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
**追記:**
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
そもそも質問文の変数がおかしかったので整理。
|
72
|
+
|
73
|
+
```PHP
|
74
|
+
|
75
|
+
$array_base = array( 187, 284 );
|
76
|
+
|
77
|
+
$array = array();
|
78
|
+
|
79
|
+
foreach ( $array_base as $id ) {
|
80
|
+
|
81
|
+
$ids = get_post_ancestors( $id );
|
82
|
+
|
83
|
+
if ( empty( $ids ) ) continue;
|
84
|
+
|
85
|
+
$scores = get_post_meta( array_pop( $ids ), 'score', true );
|
86
|
+
|
87
|
+
$tmp = [
|
88
|
+
|
89
|
+
'ids' => $id,
|
90
|
+
|
91
|
+
'scores' => $scores
|
92
|
+
|
93
|
+
];
|
94
|
+
|
95
|
+
array_push($array, $tmp);
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
var_dump( $array );
|
100
|
+
|
101
|
+
```
|
1
質問が書き換わったため追記
test
CHANGED
@@ -14,10 +14,46 @@
|
|
14
14
|
|
15
15
|
> ```
|
16
16
|
|
17
|
-
string(5) "abcde"
|
17
|
+
> string(5) "abcde"
|
18
18
|
|
19
|
-
```
|
19
|
+
> ```
|
20
20
|
|
21
21
|
>
|
22
22
|
|
23
23
|
> 「string」は変数が文字列であることを示し、( )内にはそのバイト数が表示されます。ここでは半角の英数字が5つ格納されているため「5」となります。
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
---
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
**追記:**
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```PHP
|
36
|
+
|
37
|
+
$ids = get_post_ancestors( $id );
|
38
|
+
|
39
|
+
if ( empty( $ids ) ) continue;
|
40
|
+
|
41
|
+
$scores = get_post_meta( array_pop( $id ), 'score', true );
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
【get_post_ancestors – WordPress私的マニュアル】
|
46
|
+
|
47
|
+
[https://elearn.jp/wpman/function/get_post_ancestors.html](https://elearn.jp/wpman/function/get_post_ancestors.html)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
【PHP: array_pop - Manual】
|
52
|
+
|
53
|
+
[http://php.net/manual/ja/function.array-pop.php](http://php.net/manual/ja/function.array-pop.php)
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
【PHP: array_shift - Manual】
|
58
|
+
|
59
|
+
[http://php.net/manual/ja/function.array-shift.php](http://php.net/manual/ja/function.array-shift.php)
|