Selaa lähdekoodia

feat: added custom field for override names | sorting uses name override

tags/0.9.0
J 6 vuotta sitten
vanhempi
commit
30d691ed34

+ 6
- 4
plugins/cia-endpoints/includes/class.make-sortby.php Näytä tiedosto

23
     public function by_alpha( $request ) {
23
     public function by_alpha( $request ) {
24
         global $wpdb;
24
         global $wpdb;
25
         $res = $wpdb->get_results($wpdb->prepare(
25
         $res = $wpdb->get_results($wpdb->prepare(
26
-            "SELECT * FROM wp_posts
27
-            WHERE post_type = %s 
28
-            AND post_status='publish'
29
-            ORDER BY SUBSTRING_INDEX(post_title, ' ', -1)",
26
+            "SELECT DISTINCT wp_posts.*, 
27
+            IFNULL(wp_postmeta.meta_value, SUBSTRING_INDEX(wp_posts.post_title, ' ', -1)) AS sort_name
28
+            FROM wp_posts LEFT JOIN wp_postmeta 
29
+            ON (wp_postmeta.post_id = wp_posts.ID AND wp_postmeta.meta_key='artist-sort-name') 
30
+            WHERE wp_posts.post_type='artist' AND wp_posts.post_status='publish'
31
+            ORDER BY sort_name",
30
             $this->post_type
32
             $this->post_type
31
         ));
33
         ));
32
         wp_reset_postdata();
34
         wp_reset_postdata();

+ 3
- 1
plugins/cia-endpoints/includes/formats.php Näytä tiedosto

11
     $filtered[content] = $item->post_content;
11
     $filtered[content] = $item->post_content;
12
 
12
 
13
     $filtered[hero] = get_post_meta( $item->ID, 'hero_header', true );
13
     $filtered[hero] = get_post_meta( $item->ID, 'hero_header', true );
14
-    
14
+    if($item->post_type === 'artist') {
15
+        $filtered[sortname] = get_post_meta( $item->ID, 'artist-sort-name', true );
16
+    }
15
     return $filtered;
17
     return $filtered;
16
 }
18
 }
17
 
19
 

+ 19
- 0
plugins/cia-post-types/cia-post-types.php Näytä tiedosto

128
         'render_row_cb' => 'cmb_hero_render_row_cb'
128
         'render_row_cb' => 'cmb_hero_render_row_cb'
129
     ) );
129
     ) );
130
 }
130
 }
131
+
132
+add_action( 'cmb2_admin_init', 'cmb2_artist_sort_metaboxes' );
133
+function cmb2_artist_sort_metaboxes() {
134
+    $cmb = new_cmb2_box( array(
135
+        'id'            => 'artist_sort_metabox',
136
+        'title'         => __( 'Name Override', 'cmb2' ),
137
+        'object_types'  => array( 'artist' ),
138
+        'context'       => 'normal',
139
+        'priority'      => 'high',
140
+        'show_names'    => true,
141
+        'show_in_rest'  => WP_REST_Server::READABLE
142
+    ) );
143
+    $cmb->add_field( array(
144
+        'name'             => __( 'Alternate Name', 'cmb2' ),
145
+        'desc'             => __( 'Name to use for alphabetical sorting', 'cmb2' ),
146
+        'id'               => 'artist-sort-name',
147
+        'type'             => 'text'
148
+    ) );
149
+}

Loading…
Peruuta
Tallenna