Переглянути джерело

Set order by custom field value 'lastname'

pull/2/head
Alej 2 роки тому
джерело
коміт
6ba9427deb
1 змінених файлів з 19 додано та 1 видалено
  1. 19
    1
      cvd-theme/functions.php

+ 19
- 1
cvd-theme/functions.php Переглянути файл

@@ -28,6 +28,24 @@ function set_acf_settings() {
28 28
 
29 29
 add_filter( 'acf/shortcode/allow_in_block_themes_outside_content', '__return_true' );
30 30
 
31
+// Order by custom field value by meta_key 'lastname'
32
+function my_pre_get_posts( $query ) { 
33
+    // do not modify queries in the admin
34
+    if( is_admin() ) {
35
+        return $query;       
36
+    }
37
+    // only modify queries for 'event' post type
38
+    if( isset($query->query_vars['post_type']) && $query->query_vars['post_type']) { 
39
+        $query->set('orderby', 'meta_value');    
40
+        $query->set('meta_key', 'lastname');    
41
+        $query->set('order', 'ASC');    
42
+    }
43
+    // return
44
+    return $query;
45
+}
46
+
47
+add_action('pre_get_posts', 'my_pre_get_posts');
48
+
31 49
 
32 50
 // General Settings - Set Default Featured Image Placeholder if none exists
33 51
 if ( ! class_exists( 'DefaultThumbnailID' ) ) {
@@ -86,4 +104,4 @@ if ( ! class_exists( 'DefaultThumbnailID' ) ) {
86 104
     DefaultThumbnailID::get_instance();
87 105
     }
88 106
 
89
-?>
107
+    

Завантаження…
Відмінити
Зберегти