質問編集履歴

1

追記

2017/05/06 09:11

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -25,3 +25,77 @@
25
25
 
26
26
 
27
27
  以上、よろしくお願い致します。
28
+
29
+
30
+
31
+
32
+
33
+ 追記です。
34
+
35
+ 投稿時のサイズの登録は以下のようにしています。
36
+
37
+ ```
38
+
39
+ function add_media_meta($meta, $post_id){
40
+
41
+ update_post_meta($post_id, 'height', (int) $meta['height']);
42
+
43
+ update_post_meta($post_id, 'width', (int) $meta['width']);
44
+
45
+ return $meta;
46
+
47
+ }
48
+
49
+ add_filter('wp_generate_attachment_metadata', 'add_media_meta', 10, 2);
50
+
51
+ ```
52
+
53
+ この方法では調べた限りでは term_taxonomy_id等は扱えないようですね?
54
+
55
+
56
+
57
+ そこで別途考えてみたのが以下ですが
58
+
59
+ ```
60
+
61
+ function hogehoge($post_id) {
62
+
63
+ $meta_height = $_POST[height];
64
+
65
+ if(!empty($_POST['publish']) && $meta_height == 800){
66
+
67
+ $post_id = wp_set_object_terms( $post_id, 37, 'attachment_category', true );
68
+
69
+ }
70
+
71
+ }
72
+
73
+ add_action('save_post', 'hogehoge');
74
+
75
+ ```
76
+
77
+ まったく思い通りに動きません(;^_^A
78
+
79
+ 分からないなりに考えたのが
80
+
81
+ 投稿時に height が 800 の meta_value があれば 画像の term_id 及び term_taxonomy_id に 37 をセットする、
82
+
83
+ なんですが、何か違うようです。
84
+
85
+
86
+
87
+
88
+
89
+ 以下であれば投稿時に画像サイズは無関係でID37がセットされましたが、趣旨が違うのですよね…
90
+
91
+ ```
92
+
93
+ function add_media_term($post_id){
94
+
95
+ wp_set_object_terms($post_id, 37, 'attachment_category', true);
96
+
97
+ }
98
+
99
+ add_action('add_attachment', 'add_media_term', 99, 1);
100
+
101
+ ```