質問編集履歴
4
案追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -135,3 +135,277 @@
|
|
135
135
|
|
136
136
|
|
137
137
|
**これだと記事は重複されて繰り返し自動投稿します。**
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
###別のソースの案
|
142
|
+
|
143
|
+
```ここに言語を入力
|
144
|
+
|
145
|
+
$this_posts = get_posts(
|
146
|
+
|
147
|
+
array(
|
148
|
+
|
149
|
+
'post_type' => 'page',
|
150
|
+
|
151
|
+
'page_template' => 'template-profile-info.php'
|
152
|
+
|
153
|
+
)
|
154
|
+
|
155
|
+
);
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
$this_post_titles = wp_list_pluck( $this_posts, 'post_title' );
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
// set the DB creds
|
164
|
+
|
165
|
+
$another_db_user = 'user';
|
166
|
+
|
167
|
+
$another_db_pass = 'pass';
|
168
|
+
|
169
|
+
$another_db_name = 'name';
|
170
|
+
|
171
|
+
$another_db_host = 'localhost';
|
172
|
+
|
173
|
+
$another_tb_prefix = 'wp_';
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
// setup the DB connection
|
178
|
+
|
179
|
+
$mydb = new wpdb( $another_db_user, $another_db_pass, $another_db_name, $another_db_host );
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
$mydb->set_prefix( $another_tb_prefix );
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
//一覧情報取得
|
188
|
+
|
189
|
+
$result = $mydb->get_results("
|
190
|
+
|
191
|
+
SELECT
|
192
|
+
|
193
|
+
m0.post_title,
|
194
|
+
|
195
|
+
m0.id,
|
196
|
+
|
197
|
+
m0.post_name,
|
198
|
+
|
199
|
+
m0.guid
|
200
|
+
|
201
|
+
FROM ( select post_title, id, guid, post_name from wp_posts where post_type = 'bio' AND post_status = 'publish' ) AS m0
|
202
|
+
|
203
|
+
");
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
foreach ( $result as $value ) {
|
210
|
+
|
211
|
+
if ( in_array( $value->post_title, $this_post_titles ) ) {
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
} else {
|
216
|
+
|
217
|
+
$my_access = array(
|
218
|
+
|
219
|
+
'post_author' => '1',
|
220
|
+
|
221
|
+
'post_title' => $value->post_title,
|
222
|
+
|
223
|
+
'post_status' => 'publish',
|
224
|
+
|
225
|
+
'comment_status' => 'closed',
|
226
|
+
|
227
|
+
'ping_status' => 'closed',
|
228
|
+
|
229
|
+
'post_name' => $value->post_name,
|
230
|
+
|
231
|
+
'post_type' => 'page',
|
232
|
+
|
233
|
+
'post_parent' => '115822',
|
234
|
+
|
235
|
+
'page_template' => 'template-profile-info.php'
|
236
|
+
|
237
|
+
);
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
wp_insert_post( $my_access );
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
```
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
###さらに別のソースの案
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
```ここに言語を入力
|
256
|
+
|
257
|
+
function wpse_20160318_do_db_sync() {
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
// query the DB
|
262
|
+
|
263
|
+
global $wpdb;
|
264
|
+
|
265
|
+
$result = $wpdb->get_results(
|
266
|
+
|
267
|
+
"
|
268
|
+
|
269
|
+
SELECT post_name
|
270
|
+
|
271
|
+
FROM wp_posts
|
272
|
+
|
273
|
+
WHERE post_status = 'publish'
|
274
|
+
|
275
|
+
AND post_type = 'page'
|
276
|
+
|
277
|
+
"
|
278
|
+
|
279
|
+
);
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
// for all the results, let's check against the slug.
|
288
|
+
|
289
|
+
foreach ( $result as $r ) {
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
// see if we can find it...
|
294
|
+
|
295
|
+
$post = get_page_by_path( $r->post_name );
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
// set the DB creds
|
304
|
+
|
305
|
+
$another_db_user = 'user';
|
306
|
+
|
307
|
+
$another_db_pass = 'pass';
|
308
|
+
|
309
|
+
$another_db_name = 'name';
|
310
|
+
|
311
|
+
$another_db_host = 'localhost';
|
312
|
+
|
313
|
+
$another_tb_prefix = 'wp_';
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
// setup the DB connection
|
318
|
+
|
319
|
+
$mydb = new wpdb( $another_db_user, $another_db_pass, $another_db_name, $another_db_host );
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
$mydb->set_prefix( $another_tb_prefix );
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
//一覧情報取得
|
328
|
+
|
329
|
+
$results = $mydb->get_results("
|
330
|
+
|
331
|
+
SELECT
|
332
|
+
|
333
|
+
m0.post_title,
|
334
|
+
|
335
|
+
m0.id,
|
336
|
+
|
337
|
+
m0.post_name,
|
338
|
+
|
339
|
+
m0.guid
|
340
|
+
|
341
|
+
FROM ( select post_title, id, guid, post_name from wp_posts where post_type = 'bio' AND post_status = 'publish' ) AS m0
|
342
|
+
|
343
|
+
");
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
foreach ( $results as $value ) {
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
if ( ! $post ) {
|
354
|
+
|
355
|
+
// We're cool, let's create this one.
|
356
|
+
|
357
|
+
$my_access = Array(
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
'post_author' => '1',
|
362
|
+
|
363
|
+
'post_title' => ''.$value->post_title.'',
|
364
|
+
|
365
|
+
'post_status' => 'publish',
|
366
|
+
|
367
|
+
'comment_status' => 'closed',
|
368
|
+
|
369
|
+
'ping_status' => 'closed',
|
370
|
+
|
371
|
+
'post_name' => ''.$value->post_name.'',
|
372
|
+
|
373
|
+
'post_type' => 'page',
|
374
|
+
|
375
|
+
'post_parent' => '115822',
|
376
|
+
|
377
|
+
'page_template' => 'template-profile-info.php'
|
378
|
+
|
379
|
+
);
|
380
|
+
|
381
|
+
wp_insert_post($my_access);
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
}
|
386
|
+
|
387
|
+
else {
|
388
|
+
|
389
|
+
// No need to duplicate this one
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
}
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
}
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
}
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
// using on init to make sure the DB is ready to go
|
408
|
+
|
409
|
+
add_action( 'init', 'wpse_20160318_do_db_sync' );
|
410
|
+
|
411
|
+
```
|
3
最新ソース
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,6 +9,28 @@
|
|
9
9
|
今の段階でのソースです。
|
10
10
|
|
11
11
|
```ここに言語を入力
|
12
|
+
|
13
|
+
global $wpdb;
|
14
|
+
|
15
|
+
$results = $wpdb->get_results("
|
16
|
+
|
17
|
+
SELECT post_title
|
18
|
+
|
19
|
+
FROM wp_posts
|
20
|
+
|
21
|
+
");
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
foreach ($results as $post) {
|
26
|
+
|
27
|
+
$page_exists = $post->post_title;
|
28
|
+
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
12
34
|
|
13
35
|
//その他DB接続設定
|
14
36
|
|
@@ -38,19 +60,13 @@
|
|
38
60
|
|
39
61
|
SELECT
|
40
62
|
|
41
|
-
|
63
|
+
m0.post_title,
|
42
64
|
|
43
|
-
|
65
|
+
m0.id,
|
44
66
|
|
45
|
-
|
67
|
+
m0.post_name,
|
46
68
|
|
47
|
-
|
69
|
+
m0.guid
|
48
|
-
|
49
|
-
(select m1.meta_value from wp_postmeta m1 where m1.post_id = m0.id and m1.meta_key = 'association' ) AS 'association',
|
50
|
-
|
51
|
-
(select m2.meta_value from wp_postmeta m2 where m2.post_id = m0.id and m2.meta_key = 'number' ) AS 'number',
|
52
|
-
|
53
|
-
(select m3.meta_value from wp_postmeta m3 where m3.post_id = m0.id and m3.meta_key = 'name_furigana' ) AS 'name_furigana'
|
54
70
|
|
55
71
|
FROM ( select post_title, id, guid, post_name from wp_posts where post_type = 'bio' AND post_status = 'publish' ) AS m0
|
56
72
|
|
@@ -58,41 +74,57 @@
|
|
58
74
|
|
59
75
|
|
60
76
|
|
61
|
-
$page = get_page_by_path( ''.$value->post_name.'' );
|
62
77
|
|
63
|
-
if( isset( $pages ) ) {
|
64
|
-
|
65
|
-
|
66
78
|
|
67
79
|
foreach ($result as $value) {
|
68
80
|
|
69
|
-
$my_access = Array(
|
70
81
|
|
71
|
-
'post_author' => '1',
|
72
82
|
|
73
|
-
|
83
|
+
if( $value->post_title == $page_exists ) {
|
74
84
|
|
75
|
-
'post_status' => 'publish',
|
76
85
|
|
77
|
-
'comment_status' => 'closed',
|
78
86
|
|
79
|
-
|
87
|
+
//何もしない
|
80
88
|
|
81
|
-
'post_name' => ''.$value->post_name.'',
|
82
89
|
|
83
|
-
'post_type' => 'page',
|
84
|
-
|
85
|
-
'post_parent' => '115822',
|
86
|
-
|
87
|
-
'post_content' => '本文本文本文本',
|
88
|
-
|
89
|
-
'page_template' => 'template-profile-info.php'
|
90
|
-
|
91
|
-
);
|
92
90
|
|
93
91
|
}
|
94
92
|
|
93
|
+
|
94
|
+
|
95
|
+
else {
|
96
|
+
|
97
|
+
$my_access = Array(
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
'post_author' => '1',
|
102
|
+
|
103
|
+
'post_title' => ''.$value->post_title.'',
|
104
|
+
|
105
|
+
'post_status' => 'publish',
|
106
|
+
|
107
|
+
'comment_status' => 'closed',
|
108
|
+
|
109
|
+
'ping_status' => 'closed',
|
110
|
+
|
111
|
+
'post_name' => ''.$value->post_name.'',
|
112
|
+
|
113
|
+
'post_type' => 'page',
|
114
|
+
|
115
|
+
'post_parent' => '115822',
|
116
|
+
|
117
|
+
'page_template' => 'template-profile-info.php'
|
118
|
+
|
119
|
+
);
|
120
|
+
|
121
|
+
|
122
|
+
|
95
123
|
wp_insert_post($my_access);
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
96
128
|
|
97
129
|
}
|
98
130
|
|
2
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -102,4 +102,4 @@
|
|
102
102
|
|
103
103
|
|
104
104
|
|
105
|
-
**これだと記事は重複されてしま
|
105
|
+
**これだと記事は重複されて繰り返し自動投稿します。**
|
1
詳細
test
CHANGED
File without changes
|
test
CHANGED
@@ -97,3 +97,9 @@
|
|
97
97
|
}
|
98
98
|
|
99
99
|
```
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
**これだと記事は重複されてしまいます。**
|