Skip to content
This repository was archived by the owner on May 2, 2018. It is now read-only.

Commit e521c3a

Browse files
committed
fix for A2Z when search
1 parent e56a751 commit e521c3a

2 files changed

Lines changed: 60 additions & 59 deletions

File tree

public/class-glossary.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ public function glossary_auto_link( $text ) {
235235
$this->g_tax_glossary()
236236
) {
237237
$gl_query = new WP_Query( array( 'post_type' => 'glossary', 'order' => 'ASC', 'orderby' => 'title', 'posts_per_page' => -1 ) );
238-
239238
while ( $gl_query->have_posts() ) : $gl_query->the_post();
240239
$link = get_post_meta( get_the_ID(), $this->get_plugin_slug() . '_url', true );
241240
$target = get_post_meta( get_the_ID(), $this->get_plugin_slug() . '_target', true );

public/includes/Glossary_a2z_Archive.php

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,69 +12,71 @@
1212
*/
1313
class G_a2z_Archive {
1414

15-
/**
16-
* Initialize the plugin by setting localization and loading public scripts
17-
* and styles.
18-
*
19-
* @since 1.0.0
20-
*/
21-
public function __construct() {
22-
add_filter( 'query_vars', array( $this, 'query_vars' ) );
23-
add_action( 'pre_get_posts', array( $this, 'check_qv' ) );
24-
}
15+
/**
16+
* Initialize the plugin by setting localization and loading public scripts
17+
* and styles.
18+
*
19+
* @since 1.0.0
20+
*/
21+
public function __construct() {
22+
add_filter( 'query_vars', array( $this, 'query_vars' ) );
23+
add_action( 'pre_get_posts', array( $this, 'check_qv' ) );
24+
}
2525

26-
/**
27-
* Add our value
28-
*
29-
* @param array $query_vars
30-
* @return array
31-
*/
32-
public function query_vars( $query_vars ) {
33-
array_push( $query_vars, 'az' );
34-
return $query_vars;
35-
}
26+
/**
27+
* Add our value
28+
*
29+
* @param array $query_vars
30+
* @return array
31+
*/
32+
public function query_vars( $query_vars ) {
33+
array_push( $query_vars, 'az' );
34+
return $query_vars;
35+
}
3636

37-
/**
38-
* Check our value
39-
*
40-
* @global object $wp_query
41-
* @param object $query
42-
*/
43-
public function check_qv( $query ) {
44-
global $wp_query;
45-
if ( $query->is_main_query() && isset( $wp_query->query_vars[ 'az' ] ) ) {
46-
// if we are on the main query and the query var 'a2z' exists, modify the where/orderby statements
47-
add_filter( 'posts_where', array( $this, 'modify_query_where' ) );
48-
add_filter( 'posts_orderby', array( $this, 'modify_query_orderby' ) );
49-
}
37+
/**
38+
* Check our value
39+
*
40+
* @global object $wp_query
41+
* @param object $query
42+
*/
43+
public function check_qv( $query ) {
44+
if ( $query->is_main_query() && $query->is_archive() && isset( $query->query_vars[ 'az' ] ) ) {
45+
// if we are on the main query and the query var 'a2z' exists, modify the where/orderby statements
46+
add_filter( 'posts_where', array( $this, 'modify_query_where' ) );
47+
add_filter( 'posts_orderby', array( $this, 'modify_query_orderby' ) );
5048
}
49+
}
5150

52-
/**
53-
* Alter the SQL
54-
*
55-
* @global object $wp_query
56-
* @global object $wpdb
57-
* @param string $where
58-
* @return string
59-
*/
60-
public function modify_query_where( $where ) {
61-
global $wp_query, $wpdb;
62-
$where .= " AND substring( TRIM( LEADING 'A ' FROM TRIM( LEADING 'AN ' FROM TRIM( LEADING 'THE ' FROM UPPER( $wpdb->posts.post_title ) ) ) ), 1, 1) = '" . $wp_query->query_vars[ 'az' ] . "'";
63-
return $where;
64-
}
51+
/**
52+
* Alter the SQL
53+
*
54+
* @global object $wp_query
55+
* @global object $wpdb
56+
* @param string $where
57+
* @return string
58+
*/
59+
public function modify_query_where( $where ) {
60+
global $wp_query, $wpdb;
61+
$where .= " AND substring( TRIM( LEADING 'A ' FROM TRIM( LEADING 'AN ' FROM TRIM( LEADING 'THE ' FROM UPPER( $wpdb->posts.post_title ) ) ) ), 1, 1) = '" . $wp_query->query_vars[ 'az' ] . "'";
62+
remove_filter( 'posts_where', array( $this, 'modify_query_where' ) );
63+
return $where;
64+
}
6565

66-
/**
67-
* Alter the SQL
68-
*
69-
* @global object $wpdb
70-
* @param string $orderby
71-
* @return string
72-
*/
73-
public function modify_query_orderby( $orderby ) {
74-
global $wpdb;
75-
$orderby = "( TRIM( LEADING 'A ' FROM TRIM( LEADING 'AN ' FROM TRIM( LEADING 'THE ' FROM UPPER( $wpdb->posts.post_title ) ) ) ) )";
76-
return $orderby;
77-
}
66+
/**
67+
* Alter the SQL
68+
*
69+
* @global object $wpdb
70+
* @param string $orderby
71+
* @return string
72+
*/
73+
public function modify_query_orderby( $orderby ) {
74+
global $wpdb;
75+
$orderby = "( TRIM( LEADING 'A ' FROM TRIM( LEADING 'AN ' FROM TRIM( LEADING 'THE ' FROM UPPER( $wpdb->posts.post_title ) ) ) ) )";
76+
77+
remove_filter( 'posts_orderby', array( $this, 'modify_query_orderby' ) );
78+
return $orderby;
79+
}
7880

7981
}
8082

0 commit comments

Comments
 (0)