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

質問編集履歴

4

指摘された箇所の追記

2020/03/12 12:59

投稿

Lanz
Lanz

スコア13

title CHANGED
File without changes
body CHANGED
@@ -47,4 +47,8 @@
47
47
  ```
48
48
  selectedの値を、初期の状態にしたいidに変更したのですが、実際表示するとドロップダウンのタブがその状態になっているだけで、その絞り込みが適用されていないのです。これを適用するにはどうすれば良いのでしょうか。
49
49
 
50
- お知恵を拝借できれば幸いです。よろしくお願いいたします。
50
+ お知恵を拝借できれば幸いです。よろしくお願いいたします。
51
+
52
+ ##追記
53
+ ご指摘を受けた事に関して、
54
+ 私の想定は、selectedとなった、タブに絞り込みが適用され、そのカテゴリ−のイベントだけが初期の状態から表示されていることでした。しかし、今の状態はカテゴリーごとに絞り込みされておらず、全てのイベントが表示されている状態です。

3

書式の改善

2020/03/12 12:59

投稿

Lanz
Lanz

スコア13

title CHANGED
File without changes
body CHANGED
@@ -45,4 +45,6 @@
45
45
  add_filter( 'wpmfc_calendar_taxonomy_args', 'my_wpmfc_calendar_taxonomy_args', 10, 3);
46
46
 
47
47
  ```
48
- selectedの値を、初期の状態にしたいidに変更したのですが、実際表示するとドロップダウンのタブがその状態になっているだけで、その絞り込みが適用されていないのです。これを適用するにはどうすれば良いのでしょうか。
48
+ selectedの値を、初期の状態にしたいidに変更したのですが、実際表示するとドロップダウンのタブがその状態になっているだけで、その絞り込みが適用されていないのです。これを適用するにはどうすれば良いのでしょうか。
49
+
50
+ お知恵を拝借できれば幸いです。よろしくお願いいたします。

2

質問内容の変更

2020/03/12 11:03

投稿

Lanz
Lanz

スコア13

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

1

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

2020/03/12 11:00

投稿

Lanz
Lanz

スコア13

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