teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

追記

2017/05/06 09:11

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -11,4 +11,41 @@
11
11
  画像アップロード時にそのような動作が可能なフィルターフック等があればお教えください。
12
12
  また、参考になるようなサイト等があれば併せてお願いします。
13
13
 
14
- 以上、よろしくお願い致します。
14
+ 以上、よろしくお願い致します。
15
+
16
+
17
+ 追記です。
18
+ 投稿時のサイズの登録は以下のようにしています。
19
+ ```
20
+ function add_media_meta($meta, $post_id){
21
+ update_post_meta($post_id, 'height', (int) $meta['height']);
22
+ update_post_meta($post_id, 'width', (int) $meta['width']);
23
+ return $meta;
24
+ }
25
+ add_filter('wp_generate_attachment_metadata', 'add_media_meta', 10, 2);
26
+ ```
27
+ この方法では調べた限りでは term_taxonomy_id等は扱えないようですね?
28
+
29
+ そこで別途考えてみたのが以下ですが
30
+ ```
31
+ function hogehoge($post_id) {
32
+ $meta_height = $_POST[height];
33
+ if(!empty($_POST['publish']) && $meta_height == 800){
34
+ $post_id = wp_set_object_terms( $post_id, 37, 'attachment_category', true );
35
+ }
36
+ }
37
+ add_action('save_post', 'hogehoge');
38
+ ```
39
+ まったく思い通りに動きません(;^_^A
40
+ 分からないなりに考えたのが
41
+ 投稿時に height が 800 の meta_value があれば 画像の term_id 及び term_taxonomy_id に 37 をセットする、
42
+ なんですが、何か違うようです。
43
+
44
+
45
+ 以下であれば投稿時に画像サイズは無関係でID37がセットされましたが、趣旨が違うのですよね…
46
+ ```
47
+ function add_media_term($post_id){
48
+ wp_set_object_terms($post_id, 37, 'attachment_category', true);
49
+ }
50
+ add_action('add_attachment', 'add_media_term', 99, 1);
51
+ ```