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

回答編集履歴

1

タクソノミーを降順と余分なif削除

2017/06/07 14:33

投稿

madone99
madone99

スコア1857

answer CHANGED
@@ -6,11 +6,10 @@
6
6
  function custom_main_query( $query ) {
7
7
  if ( is_admin() || !$query->is_main_query() ) return;
8
8
 
9
- if ( $query->is_tax('prefectures') ) {
10
9
  $query->set('post_type', 'カスタム投稿名' );
11
10
  $query->set('post_status', 'publish');
12
11
 
13
- $taxquery[] = array(
12
+  $taxquery[] = array(
14
13
  'taxonomy' => 'タクソノミー名',
15
14
  'terms' => ターム,
16
15
  'field' => 'name',
@@ -29,26 +28,17 @@
29
28
  'value' => $currnet_date,
30
29
  'compare' => '>',
31
30
  'type' => 'DATE'
32
- ),
33
- array(
34
- 'key' => 'カスタムフィールド名3',
35
- 'value' => '1',
36
- 'compare' => '!='
37
- ),
38
- 'meta3' => array(
39
- 'key' => 'カスタムフィールド名4',
40
- 'type' => 'NUMERIC'
41
- )
31
+ )
42
32
  );
33
+ $query->set('meta_query',$metaquery);
43
34
 
44
- $query->set('meta_query',$metaquery);
35
+ $query->set( 'order', 'desc' );
45
36
  $query->set('orderby',array(
46
37
  'meta1' => 'DESC',
47
38
  'meta2' => 'ASC',
48
39
  'date' => 'DESC'
49
40
  )
50
41
  );
51
- }
52
42
 
53
43
  }
54
44
  add_action( 'pre_get_posts', 'custom_main_query' );