Просмотр исходного кода

:sparkles: added materials taxonomy to artists | exposing materials to endpoint

tags/0.9.0
j 5 лет назад
Родитель
Сommit
5792da7d6a
2 измененных файлов: 24 добавлений и 17 удалений
  1. 12
    7
      plugins/cia-endpoints/includes/formats.php
  2. 12
    10
      plugins/cia-post-types/cia-post-types.php

+ 12
- 7
plugins/cia-endpoints/includes/formats.php Просмотреть файл

@@ -14,15 +14,20 @@ function default_post_format( $item ) {
14 14
 
15 15
     if($item->post_type === 'artist') {
16 16
         $filtered[sortname] = get_post_meta( $item->ID, 'artist-sort-name', true );
17
-    
18
-        // Parse category IDs and store just the slugs
19
-        $category_slugs = [];
20
-        foreach (wp_get_post_categories( $item->ID ) as $id):
21
-            $category = get_category($id);
22
-            array_push($category_slugs, $category->slug);
17
+        $material_slugs = [];
18
+        foreach (get_the_terms( $item, 'material' ) as $material_slug):
19
+            array_push($material_slugs, $material_slug->slug);
23 20
         endforeach;
24
-        $filtered[categories] = $category_slugs;
21
+        $filtered[materials] = $material_slugs;
25 22
     }
23
+    
24
+    // Parse category IDs and store just the slugs
25
+    $category_slugs = [];
26
+    foreach (wp_get_post_categories( $item->ID ) as $id):
27
+        $category = get_category($id);
28
+        array_push($category_slugs, $category->slug);
29
+    endforeach;
30
+    $filtered[categories] = $category_slugs;
26 31
 
27 32
     return $filtered;
28 33
 }

+ 12
- 10
plugins/cia-post-types/cia-post-types.php Просмотреть файл

@@ -71,6 +71,17 @@ foreach ($custom_types as $type):
71 71
     add_action( 'init', [ $custom_type_instance, 'register_post_type' ], 10 );
72 72
 endforeach;
73 73
 
74
+/**
75
+ * Create taxonomies
76
+ */
77
+
78
+add_action('init', 'create_materials_taxonomy'); 
79
+function create_materials_taxonomy() {
80
+    $post_types_that_show_materials = [ 'artist' ];
81
+    register_taxonomy('material', $post_types_that_show_materials, [ "label" => "Materials"]);
82
+}
83
+/* Plugin Logic -- END * /
84
+
74 85
 /**
75 86
  * Custom Fields
76 87
  * Defining our HERO, and Name override fields
@@ -150,13 +161,4 @@ function cmb2_artist_sort_metaboxes() {
150 161
         'id'               => 'artist-sort-name',
151 162
         'type'             => 'text'
152 163
     ) );
153
-}
154
-
155
-/**
156
- * Create taxonomies
157
- */
158
-add_action('init', 'create_materials_taxonomy'); 
159
-function create_materials_taxonomy() {
160
-    $post_types_that_show_materials = [ 'artist' ];
161
-    register_taxonomy("material", $post_types_that_show_materials, [ "label" => "Materials"]);
162
-}
164
+}

Загрузка…
Отмена
Сохранить