質問編集履歴

1

va-simple-expiresを"利用している"という表現を、参考にしていると変更。コードを追記。

2016/07/02 02:38

投稿

rela
rela

スコア8

test CHANGED
@@ -1 +1 @@
1
- [Wordpress]csvで登録した投稿のカテゴリーを指定日時に変更する方法
1
+ [Wordpress]csvで登録した投稿のカテゴリーを指定日時に変更する方法
test CHANGED
@@ -30,7 +30,7 @@
30
30
 
31
31
  ###試したこと
32
32
 
33
- [この記事](http://publictestzone.com/ptz/blog/set-expiration-date-to-wordpress-posts-imported-from-csv-file/)を参考に、該当するpostの取得には [va-simple-expires](https://ja.wordpress.org/plugins/va-simple-expires/)を利用させていただいています。
33
+ [この記事](http://publictestzone.com/ptz/blog/set-expiration-date-to-wordpress-posts-imported-from-csv-file/)を参考に、該当するpostの取得には [va-simple-expires](https://ja.wordpress.org/plugins/va-simple-expires/)を参考に組み立てています。[「利用させていただいています。」からご指摘により変更]
34
34
 
35
35
 
36
36
 
@@ -44,13 +44,79 @@
44
44
 
45
45
  ###該当のソースコード
46
46
 
47
- ```php
48
47
 
48
+
49
- global $wpdb;
49
+ **dr-simple-category-changer.php**
50
50
 
51
51
 
52
52
 
53
+ ```php
54
+
55
+ <?php
56
+
57
+ if ( !function_exists( 'dr_simple_category_changer_setup' ) ) :
58
+
59
+ function dr_simple_category_changer_setup() {
60
+
61
+ if ( !class_exists( 'DR_SIMPLE_CATEGORY_CHANGER_SETUP' ) ) {
62
+
63
+ class DR_SIMPLE_CATEGORY_CHANGER_SETUP extends _DR_SIMPLE_CATEGORY_CHANGER {
64
+
65
+ protected function __construct() {
66
+
67
+ parent::__construct();
68
+
69
+ }
70
+
71
+ }
72
+
73
+ }
74
+
75
+
76
+
77
+ $dr_simple_category_changer = DR_SIMPLE_CATEGORY_CHANGER_SETUP::instance();
78
+
79
+ }
80
+
81
+ endif; // dr_simple_category_changer_setup
82
+
83
+ add_action( 'plugins_loaded', 'dr_simple_category_changer_setup' );
84
+
85
+
86
+
87
+ ```
88
+
89
+
90
+
91
+ ** 以下は同一ファイル内`class _DR_SIMPLE_CATEGORY_CHANGER` 内になります**
92
+
93
+
94
+
95
+ ```php
96
+
97
+ protected function __construct() {
98
+
99
+ add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
100
+
101
+ add_action( 'init', array( &$this, 'simple_category_changer' ) );
102
+
103
+ }
104
+
105
+ ```
106
+
107
+
108
+
109
+ ```php
110
+
111
+
112
+
113
+ function simple_category_changer() {
114
+
115
+ global $wpdb;
116
+
117
+
118
+
53
- $result = $wpdb->get_results( $wpdb->prepare("
119
+ $result = $wpdb->get_results( $wpdb->prepare("
54
120
 
55
121
  SELECT postmetadate.post_id
56
122
 
@@ -76,17 +142,17 @@
76
142
 
77
143
 
78
144
 
79
- $term = term_exists('past', 'category');
145
+ $term = term_exists('past', 'category');
80
146
 
81
147
 
82
148
 
83
149
 
84
150
 
85
- if ( ! empty( $result ) && !empty($term )) :
151
+ if ( ! empty( $result ) && !empty($term )) :
86
152
 
87
- $update_post = array();
153
+ $update_post = array();
88
154
 
89
- foreach ( $result as $cur_post ) :
155
+ foreach ( $result as $cur_post ) :
90
156
 
91
157
  remove_action( 'simple_category_changer','save_post' );
92
158
 
@@ -94,8 +160,12 @@
94
160
 
95
161
  add_action( 'simple_category_changer','save_post' );
96
162
 
97
- endforeach;
163
+ endforeach;
98
164
 
99
- endif;
165
+ endif;
166
+
167
+
168
+
169
+ }
100
170
 
101
171
  ```