質問編集履歴

4

指摘された箇所の追記

2020/03/12 12:59

投稿

Lanz
Lanz

スコア13

test CHANGED
File without changes
test CHANGED
@@ -97,3 +97,11 @@
97
97
 
98
98
 
99
99
  お知恵を拝借できれば幸いです。よろしくお願いいたします。
100
+
101
+
102
+
103
+ ##追記
104
+
105
+ ご指摘を受けた事に関して、
106
+
107
+ 私の想定は、selectedとなった、タブに絞り込みが適用され、そのカテゴリ−のイベントだけが初期の状態から表示されていることでした。しかし、今の状態はカテゴリーごとに絞り込みされておらず、全てのイベントが表示されている状態です。

3

書式の改善

2020/03/12 12:59

投稿

Lanz
Lanz

スコア13

test CHANGED
File without changes
test CHANGED
@@ -93,3 +93,7 @@
93
93
  ```
94
94
 
95
95
  selectedの値を、初期の状態にしたいidに変更したのですが、実際表示するとドロップダウンのタブがその状態になっているだけで、その絞り込みが適用されていないのです。これを適用するにはどうすれば良いのでしょうか。
96
+
97
+
98
+
99
+ お知恵を拝借できれば幸いです。よろしくお願いいたします。

2

質問内容の変更

2020/03/12 11:03

投稿

Lanz
Lanz

スコア13

test CHANGED
@@ -1 +1 @@
1
- ACFでユーザーごとにランク情報を付与し、EventsManagerイベントカテゴリーに紐付けて、そのランクだけイベントを表示するようにしたい
1
+ wp_dropdown_categories()で初期状態選択が反映されるようにしたい
test CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  現在、、WordpressでEvents ManagerとFullCalendarを使用してイベントを管理するサイトを作っています。
4
4
 
5
+
6
+
5
- 実現したいのは、ACFでユーザーごとにランク情報を付与し、それとEventsManagerイベントカテゴリーに紐付けて、そのランクだけのイベントを表示するようにしたいです。
7
+ 実現したいのは、Fullcalendarの絞り込み機能の、wp_dropdown_categories()で初期状態選択が反映されるようにしたいです。
6
8
 
7
9
 
8
10
 
@@ -10,96 +12,84 @@
10
12
 
11
13
 
12
14
 
13
- em-posts.phpの
15
+ wp-fullcalendar.phpの
14
16
 
15
17
  ```php
16
18
 
17
- if( get_option('dbem_categories_enabled', true) ){
19
+ <div class="wpfc-calendar-wrapper"><form class="wpfc-calendar"></form><div class="wpfc-loading"></div></div>
18
20
 
19
- $supported_array = (EM_MS_GLOBAL && !is_main_site()) ? array():array(EM_POST_TYPE_EVENT,'event-recurring');
21
+ <div class="wpfc-calendar-search" style="display:none;">
20
22
 
21
- register_taxonomy(EM_TAXONOMY_CATEGORY,$supported_array, apply_filters('em_ct_categories', array(
23
+ <?php
22
24
 
23
- 'hierarchical' => true,
25
+ $post_type = !empty(self::$args['type']) ? self::$args['type']:'post';
24
26
 
25
- 'public' => true,
27
+ //figure out what taxonomies to show
26
28
 
27
- 'show_ui' => true,
29
+ $wpfc_post_taxonomies = get_option('wpfc_post_taxonomies');
28
30
 
29
- 'query_var' => true,
31
+ $search_taxonomies = !empty($wpfc_post_taxonomies[$post_type]) ? array_keys($wpfc_post_taxonomies[$post_type]):array();
30
32
 
31
- 'rewrite' => array('slug' => EM_TAXONOMY_CATEGORY_SLUG, 'hierarchical' => true,'with_front'=>false),
33
+ if( !empty($args['taxonomies']) ){
32
34
 
33
- 'update_count_callback' => '',
35
+ //we accept taxonomies in arguments
34
36
 
35
- 'show_tagcloud' => true,
37
+ $search_taxonomies = explode(',',$args['taxonomies']);
36
38
 
37
- 'show_in_nav_menus' => true,
39
+ array_walk($search_taxonomies, 'trim');
38
40
 
39
- 'label' => __('Event Categories','events-manager'),
41
+ unset(self::$args['taxonomies']);
40
42
 
41
- 'singular_label' => __('Event Category','events-manager'),
43
+ }
42
44
 
43
- 'labels' => array(
45
+ //go through each post type taxonomy and display if told to
44
46
 
45
- 'name'=>__('Event Categories','events-manager'),
47
+ foreach( get_object_taxonomies($post_type) as $taxonomy_name ){
46
48
 
47
- 'singular_name'=>__('Event Category','events-manager'),
49
+ $taxonomy = get_taxonomy($taxonomy_name);
48
50
 
49
- 'search_items'=>__('Search Event Categories','events-manager'),
51
+ if( count(get_terms($taxonomy_name, array('hide_empty'=>1))) > 0 && in_array($taxonomy_name, $search_taxonomies) ){
50
52
 
51
- 'popular_items'=>__('Popular Event Categories','events-manager'),
53
+ $default_value = !empty(self::$args[$taxonomy_name]) ? self::$args[$taxonomy_name]:0;
52
54
 
53
- 'all_items'=>__('All Event Categories','events-manager'),
55
+ $taxonomy_args = array( 'echo'=>true, 'hide_empty' => 1, 'name' => $taxonomy_name, 'hierarchical' => true, 'class' => 'wpfc-taxonomy '.$taxonomy_name, 'taxonomy' => $taxonomy_name, 'selected'=> $default_value, 'show_option_all' => $taxonomy->labels->all_items);
54
56
 
55
- 'parent_items'=>__('Parent Event Categories','events-manager'),
57
+ wp_dropdown_categories( apply_filters('wpmfc_calendar_taxonomy_args', $taxonomy_args, $taxonomy ) );
56
58
 
57
- 'parent_item_colon'=>__('Parent Event Category:','events-manager'),
59
+ }
58
60
 
59
- 'edit_item'=>__('Edit Event Category','events-manager'),
61
+ }
60
62
 
61
- 'update_item'=>__('Update Event Category','events-manager'),
63
+ do_action('wpfc_calendar_search', self::$args);
62
64
 
63
- 'add_new_item'=>__('Add New Event Category','events-manager'),
65
+ ?>
64
66
 
65
- 'new_item_name'=>__('New Event Category Name','events-manager'),
67
+ </div>
66
68
 
67
- 'separate_items_with_commas'=>__('Separate event categories with commas','events-manager'),
68
-
69
- 'add_or_remove_items'=>__('Add or remove events','events-manager'),
70
-
71
- 'choose_from_the_most_used'=>__('Choose from most used event categories','events-manager'),
72
-
73
- ),
69
+ ```
74
-
75
- 'capabilities' => array(
76
-
77
- 'manage_terms' => 'edit_event_categories',
78
-
79
- 'edit_terms' => 'edit_event_categories',
80
-
81
- 'delete_terms' => 'delete_event_categories',
82
-
83
- 'assign_terms' => 'edit_events',
84
-
85
- )
86
70
 
87
71
 
88
72
 
89
- )
73
+ ここのapply_filters('wpmfc_calendar_taxonomy_args', $taxonomy_args, $taxonomy )でフックし、
90
74
 
91
-
92
75
 
93
- ));
94
76
 
77
+ ```php
78
+
79
+ function my_wpmfc_calendar_taxonomy_args( $taxonomy_args, $taxonomy ){
80
+
81
+ $taxonomy_args['show_option_all'] = '';
82
+
83
+ $taxonomy_args['selected'] = 5;
84
+
85
+ return $taxonomy_args;
86
+
95
- }
87
+ }
88
+
89
+ add_filter( 'wpmfc_calendar_taxonomy_args', 'my_wpmfc_calendar_taxonomy_args', 10, 3);
90
+
91
+
96
92
 
97
93
  ```
98
94
 
99
- この辺で、カテゴリの受け渡しをしているのかなと考えているのですが、ここでどう絞り込みしていけば良いかで詰んでしまっています。
100
-
101
- #追記
102
-
103
- 現在、FullCalendarのオプションでドロップダウンの絞り込みが追加できることを今更発見しました。wpmfc_calendar_taxonomy_args()でフックして、select要素のselectedをログインユーザーのランクにセットできれば、、、という状態です。
104
-
105
- しかし、selectedを合わせてもドロップダウンの変わっているだけで、絞り込み自体はされない状態です。
95
+ selectedの値、初期の状態にしたいidに変更したのですが、実際表示するとドロップダウンのタブその状態になっているだけで、その絞り込みが適用されていないです。これを適用するにはどうすれば良いのでしょうか。

1

FullCalendar側のwpmfc_calendar_taxonomy_args()のフックで解決できないか追記しました。

2020/03/12 11:00

投稿

Lanz
Lanz

スコア13

test CHANGED
File without changes
test CHANGED
@@ -97,3 +97,9 @@
97
97
  ```
98
98
 
99
99
  この辺で、カテゴリの受け渡しをしているのかなと考えているのですが、ここでどう絞り込みしていけば良いかで詰んでしまっています。
100
+
101
+ #追記
102
+
103
+ 現在、FullCalendarのオプションでドロップダウンの絞り込みが追加できることを今更発見しました。wpmfc_calendar_taxonomy_args()でフックして、select要素のselectedをログインユーザーのランクにセットできれば、、、という状態です。
104
+
105
+ しかし、selectedを合わせてもドロップダウンの値が変わっているだけで、絞り込み自体はされない状態です。