Changeset 1920390
- Timestamp:
- 08/06/2018 12:07:57 PM (8 years ago)
- Location:
- basepress/trunk
- Files:
-
- 4 edited
-
basepress.php (modified) (2 diffs)
-
includes/class-basepress-cpt.php (modified) (1 diff)
-
public/class-basepress-search.php (modified) (7 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
basepress/trunk/basepress.php
r1910839 r1920390 5 5 * Plug URI: http://www.8bitsinarow.com 6 6 * Description: The perfect Knowledge Base plugin for WordPress 7 * Version: 1.8. 57 * Version: 1.8.6 8 8 * Author: 8Bits in a row 9 9 * Author URI: http://www.8bitsinarow.com … … 73 73 * @var string 74 74 */ 75 public $ver = '1.8. 5' ;75 public $ver = '1.8.6' ; 76 76 /** 77 77 * Database version -
basepress/trunk/includes/class-basepress-cpt.php
r1833522 r1920390 554 554 if ( 'edit' == $action && 'knowledgebase' == $post_type ) { 555 555 $missing_options = array(); 556 if ( empty(get_the_terms( $post->ID, 'knowledgebase_cat' )[0]) ) { 556 $post_terms = get_the_terms( $post->ID, 'knowledgebase_cat' )[0]; 557 $post_meta = get_post_meta( $post->ID, 'basepress_template_name', true ); 558 if ( empty($post_terms) ) { 557 559 $missing_options[] = __( 'Section', 'basepress' ); 558 560 } 559 if ( empty( get_post_meta( $post->ID, 'basepress_template_name', true )) ) {561 if ( empty($post_meta) ) { 560 562 $missing_options[] = __( 'Template', 'basepress' ); 561 563 } -
basepress/trunk/public/class-basepress-search.php
r1910839 r1920390 334 334 335 335 $terms = str_replace( '+', ' ', $terms ); 336 $query_pieces = $this->query_pieces( $product, $terms );336 $query_pieces = $this->query_pieces( $product, $terms, $pieces ); 337 337 338 338 if ( $query_pieces ) { … … 368 368 * 369 369 * @since 1.2.1 370 * @updated 1.4.0, 1.7.5, 1.7.11, 1.8.1 370 * @updated 1.4.0, 1.7.5, 1.7.11, 1.8.1, 1.8.6 371 371 * 372 372 * @param $product … … 374 374 * @return array|null|object 375 375 */ 376 private function query_pieces( $product, $terms ) { 376 private function query_pieces( $product, $terms, $pieces = array() ) { 377 377 378 global $wpdb; 378 379 … … 384 385 $terms = strtolower( $terms ); 385 386 } 387 388 //Set exact matches terms before filtering the query 389 $exact_match_terms = $terms; 390 386 391 //Filter out unwanted terms 387 392 $terms = $this->filter_terms( $terms ); … … 421 426 422 427 $_sections_ids = $wpdb->get_results( $sections_query, ARRAY_A ); 423 428 424 429 $sections_ids = array(); 425 430 … … 431 436 432 437 //Prepare matches portion of the query 438 $order_index = 1; 433 439 $orderby = ''; 434 foreach ( $sql_terms as $sql_term ) { 435 $orderby .= " + CASE WHEN $wpdb->posts.post_content LIKE '$sql_term%' THEN 1 ELSE 0 END"; 436 $orderby .= " + CASE WHEN $wpdb->posts.post_title LIKE '$sql_term%' THEN 1 ELSE 0 END"; 437 } 438 $orderby = ltrim( $orderby, ' + ' ); 439 $orderby .= " DESC"; 440 440 441 //Exact matches 442 $orderby .= " WHEN $wpdb->posts.post_title REGEXP '[[:<:]]$exact_match_terms' THEN $order_index"; 443 $order_index++; 444 $orderby .= " WHEN $wpdb->posts.post_content REGEXP '[[:<:]]$exact_match_terms' THEN $order_index"; 445 $order_index++; 446 447 //AND logic 448 foreach( array( 'title', 'content' ) as $field ){ 449 $orderby .= ' WHEN'; 450 foreach( $sql_terms as $index => $sql_term ){ 451 $sql_term = $sql_term; 452 $orderby .= $index != 0 ? ' AND' : ''; 453 $orderby .= " $wpdb->posts.post_$field REGEXP '[[:<:]]$sql_term'"; 454 } 455 $orderby .= " THEN $order_index"; 456 $order_index++; 457 } 458 459 //OR logic 460 foreach( array( 'title', 'content' ) as $field ){ 461 $orderby .= ' WHEN'; 462 foreach( $sql_terms as $index => $sql_term ){ 463 $sql_term = $sql_term; 464 $orderby .= $index != 0 ? ' OR' : ''; 465 $orderby .= " $wpdb->posts.post_$field REGEXP '[[:<:]]$sql_term'"; 466 } 467 $orderby .= " THEN $order_index"; 468 $order_index++; 469 } 470 471 //Close ORDER BY clause 472 $orderby = '(CASE ' . ltrim( $orderby, ' + ' ) . " ELSE $order_index END)"; 473 474 //Join Clause 441 475 $pieces['join'] = " LEFT JOIN $wpdb->term_relationships AS t ON ($wpdb->posts.ID = t.object_id)"; 442 476 477 //Where Clause 443 478 $pieces['where'] = " AND t.term_taxonomy_id IN ($sections_ids)"; 444 479 $pieces['where'] .= " AND ( LOWER($wpdb->posts.post_content) REGEXP '$multi_terms' OR LOWER($wpdb->posts.post_title) REGEXP '$multi_terms' )"; … … 449 484 450 485 /** 451 * Filter to alter the query pieces for the search query452 */453 $pieces = apply_filters( 'basepress_search_query_pieces', $pieces );486 * Filter to alter the query pieces for the search query 487 */ 488 $pieces = apply_filters( 'basepress_search_query_pieces', $pieces ); 454 489 455 490 $pieces['orderby'] .= ", $wpdb->posts.post_date DESC"; -
basepress/trunk/readme.txt
r1910839 r1920390 5 5 Requires at least: 4.5 6 6 Tested up to: 4.9 7 Stable tag: 1.8. 57 Stable tag: 1.8.6 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 138 138 == Changelog == 139 139 140 = 1.8.6 = 141 * Improved search results to move exact matches on top 142 140 143 = 1.8.5 = 141 144 * Removed page builders' shortcodes from search snippets
Note: See TracChangeset
for help on using the changeset viewer.