質問編集履歴

3

編集した

2017/06/21 02:40

投稿

spellbound
spellbound

スコア190

test CHANGED
File without changes
test CHANGED
@@ -100,7 +100,7 @@
100
100
 
101
101
 
102
102
 
103
- // term_relationshipsテーブルに情報を入れて紐付ける
103
+ // term_relationships
104
104
 
105
105
  $postId = $id->post_id;
106
106
 

2

追記しました。

2017/06/21 02:40

投稿

spellbound
spellbound

スコア190

test CHANGED
File without changes
test CHANGED
@@ -44,6 +44,78 @@
44
44
 
45
45
  ```
46
46
 
47
+ #foreach文
48
+
49
+ ```php
50
+
51
+ foreach (array($ids) as $id) {
52
+
53
+ $exId = $id->meta_value;
54
+
55
+ $json = getExData($exId);
56
+
57
+ $exNm = $json->ExList[0]->ExNm;
58
+
59
+ $prefNm = $json->ExList[0]->PrefNm;
60
+
61
+ $areaNm = $json->ExList[0]->AreaNm;
62
+
63
+ $latitude = $json->ExList[0]->Latitude;
64
+
65
+ $longitude = $json->ExList[0]->Longitude;
66
+
67
+ $exInnCd = $json->ExList[0]->ExInnCd;
68
+
69
+ $exSaleCd = $json->ExList[0]->ExSaleCd;
70
+
71
+ $timestamp = time();
72
+
73
+ $updatedAt = date("Y-m-d H:i:s", $timestamp);
74
+
75
+
76
+
77
+ // wp_exs
78
+
79
+ $acmData = compact("exId", "exNm", "prefNm", "areaNm", "latitude", "longitude", "exInnCd", "exSaleCd", "updatedAt");
80
+
81
+ insertDataToExsTable($acmData, $wpdb);
82
+
83
+
84
+
85
+ // wp_terms
86
+
87
+ $encodedExNm = rawurlencode($exNm);
88
+
89
+ $tagData = compact("exNm", "encodedExNm");
90
+
91
+ insertDataToTermsTable($tagData, $wpdb);
92
+
93
+
94
+
95
+ // wp_term_taxonomy
96
+
97
+ $termId = $wpdb->get_var("SELECT term_id FROM wp_terms WHERE name = '$exNm'");
98
+
99
+ insertDataToTermTaxonomyTable($termId, $wpdb);
100
+
101
+
102
+
103
+ // term_relationshipsテーブルに情報を入れて紐付ける
104
+
105
+ $postId = $id->post_id;
106
+
107
+ $termTaxonomyId = $wpdb->get_var("SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE term_id = '$termId'");
108
+
109
+ $relationshipData = compact("postId", "termTaxonomyId");
110
+
111
+ insertDataToTermRelationships($relationshipData, $wpdb);
112
+
113
+ }
114
+
115
+ ```
116
+
117
+
118
+
47
119
  #エラーコード
48
120
 
49
121
  - Warning: Invalid argument supplied for foreach()

1

誤植

2017/06/21 02:40

投稿

spellbound
spellbound

スコア190

test CHANGED
@@ -1 +1 @@
1
- [WordPress] get_resultsを使ったコード関数化できない
1
+ [WordPress] get_resultsを使ったコード関数化できない
test CHANGED
File without changes