質問編集履歴

1

修正を入力しました。2017-01-22 20:01

2017/01/22 11:07

投稿

SoraSue
SoraSue

スコア30

test CHANGED
File without changes
test CHANGED
@@ -229,3 +229,173 @@
229
229
  ###補足情報
230
230
 
231
231
  申し訳ございませんが、今はローカル開発環境上でサイトを作っていますので、サイトを直接お見せすることができません。
232
+
233
+
234
+
235
+ ###追記(2017-01-22 20:01)
236
+
237
+ 以下のようにコードを修正したところ、データベースに新しく情報が保存されるようになりました。しかし、id,user_id,component,type,data_recorded以外はデータが0として保存されてしまいます。
238
+
239
+
240
+
241
+ ```php
242
+
243
+ function ShareHow(){
244
+
245
+ if ( bp_has_members( bp_ajax_querystring( 'members' ) ) ) :
246
+
247
+ while ( bp_members() ) : bp_the_member();
248
+
249
+ global $wpdb,$bp;
250
+
251
+ //ユーザーIDと完了したタスクの内容、タスクを完了して成長したことを取得。
252
+
253
+ $MyUserID = $bp->loggedin_user->id;
254
+
255
+ $ThisToDo = filter_input(INPUT_POST, 'ThisToDo');
256
+
257
+ $HowCan = filter_input(INPUT_POST, 'HowCan');
258
+
259
+ //現在時刻を取得
260
+
261
+ $Now = new DateTime();
262
+
263
+ $Now = $Now->setTimeZone( new DateTimeZone('Asia/Tokyo'));
264
+
265
+ $Now = $Now->format(YmdHis);
266
+
267
+ $act = 'activity';
268
+
269
+ $act_up = 'activity_update';
270
+
271
+ $table_name = $wpdb->prefix . 'bp_activity';
272
+
273
+ //最新のアクティビティの投稿を取得
274
+
275
+ $MaxDate = $wpdb->get_results("
276
+
277
+ SELECT MAX(date_recorded)
278
+
279
+ FROM $table_name
280
+
281
+ WHERE `user_id` = $MyUserID
282
+
283
+ AND `component` = '$act'
284
+
285
+ AND `type` = '$act_up'
286
+
287
+ ", ARRAY_A );
288
+
289
+ foreach((array)$MaxDate as $item) {
290
+
291
+ $Max = $item['MAX(date_recorded)'];
292
+
293
+ }
294
+
295
+ //$Max = join(",",$Max);
296
+
297
+
298
+
299
+ //$Max = $Max->format(YmdHis);
300
+
301
+
302
+
303
+ //新しいアクティビティの投稿として認識されるために必要な情報を取得
304
+
305
+ $activity = $wpdb->get_results("
306
+
307
+ SELECT action, primary_link, item_id, secondary_item_id, mptt_left, mptt_right, is_spam
308
+
309
+ FROM $table_name
310
+
311
+ WHERE `user_id` = $MyUserID
312
+
313
+ AND `component` = '$act'
314
+
315
+ AND `type` = '$act_up'
316
+
317
+ AND `date_recorded` = 20170121100157
318
+
319
+ ", ARRAY_A );
320
+
321
+ foreach((array)$activity as $item) {
322
+
323
+ $action = $item['action'] ;
324
+
325
+ $primary_link = $item['primary_link'] ;
326
+
327
+ $item_id = $item['item_id'] ;
328
+
329
+ $secondary_item_id = $item['secondary_item_id'] ;
330
+
331
+ $mptt_left = $item['mptt_left'] ;
332
+
333
+ $mptt_right = $item['mptt_right'] ;
334
+
335
+ $is_spam = $item['is_spam'] ;
336
+
337
+ }
338
+
339
+
340
+
341
+ $content = "私は+$ThisToDo+を完了して+次のように成長しました。+$HowCan";
342
+
343
+
344
+
345
+ //テーブルに保存
346
+
347
+ $wpdb->insert($table_name,
348
+
349
+ array(
350
+
351
+ 'user_id' => $MyUserID,
352
+
353
+ 'component' => $act,
354
+
355
+ 'type' => $act_up,
356
+
357
+ 'action' => $action,
358
+
359
+ 'content' => $content,
360
+
361
+ 'primary_link' => $primary_link,
362
+
363
+ 'item_id' => $item_id,
364
+
365
+ 'secondary_item_id' => $secondary_item_id,
366
+
367
+ 'date_recorded' => $Now,
368
+
369
+ 'mptt_left' => $mptt_left,
370
+
371
+ 'mptt_right' => $mptt_right,
372
+
373
+ 'is_spam' => $is_spam
374
+
375
+ ),
376
+
377
+ array(
378
+
379
+ '%d','%s','%s'
380
+
381
+
382
+
383
+ )
384
+
385
+ );
386
+
387
+
388
+
389
+ die();
390
+
391
+ endwhile ;
392
+
393
+ endif;
394
+
395
+ }
396
+
397
+ add_action( 'wp_ajax_ShareHow', 'ShareHow' );
398
+
399
+
400
+
401
+ ```