Ticket #41266: 41266.patch
File 41266.patch, 2.3 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-meta-query.php
95 95 protected $has_or_relation = false; 96 96 97 97 /** 98 * The default meta table alias. 99 * 100 * @var string 101 */ 102 protected $default_meta_table_alias = 'mt'; 103 104 /** 98 105 * Constructor. 99 106 * 100 107 * @since 3.2.0 … … 511 518 $alias = $this->find_compatible_table_alias( $clause, $parent_query ); 512 519 if ( false === $alias ) { 513 520 $i = count( $this->table_aliases ); 514 $alias = $i ? 'mt'. $i : $this->meta_table;521 $alias = $i ? $this->default_meta_table_alias . $i : $this->meta_table; 515 522 516 523 // JOIN clauses for NOT EXISTS have their own syntax. 517 524 if ( 'NOT EXISTS' === $meta_compare ) { … … 727 734 public function has_or_relation() { 728 735 return $this->has_or_relation; 729 736 } 737 738 /** 739 * Sets default meta table alias. 740 * 741 * @param string $default_meta_table_alias The default meta table alias. 742 * 743 * @return void 744 */ 745 public function set_default_meta_table_alias( $default_meta_table_alias ) { 746 $this->default_meta_table_alias = $default_meta_table_alias; 747 } 730 748 } -
tests/phpunit/tests/meta/query.php
884 884 885 885 $this->assertTrue( $q->has_or_relation() ); 886 886 } 887 888 /** 889 * Test that a custom default_meta_table_alias can be set. 890 * @ticket 41266 891 */ 892 public function test_set_default_meta_table_alias() { 893 global $wpdb; 894 895 $query = new WP_Meta_Query(); 896 897 $query->set_default_meta_table_alias( 'myalias' ); 898 899 $the_complex_query[ 'meta_query' ] = array( 900 array( 'key' => 'my_first_key', 'value' => 'my_amazing_value' ), 901 array( 'key' => 'my_second_key', 'compare' => 'NOT EXISTS' ), 902 array( 'key' => 'my_third_key', 'value' => array(), 'compare' => 'IN' ), 903 ); 904 905 $query->parse_query_vars( $the_complex_query ); 906 907 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); 908 909 $this->assertContains( 'AS myalias1', $sql[ 'join' ] ); 910 $this->assertContains( 'AS myalias2', $sql[ 'join' ] ); 911 } 887 912 }