[wp-trac] [WordPress Trac] #44658: Support BETWEEN for term names in WP_Tax_Query/WP_Term_Query

WordPress Trac noreply at wordpress.org
Wed Mar 6 03:07:22 UTC 2019


#44658: Support BETWEEN for term names in WP_Tax_Query/WP_Term_Query
-------------------------------------------------+-------------------------
 Reporter:  soulseekah                           |       Owner:  (none)
     Type:  feature request                      |      Status:  new
 Priority:  normal                               |   Milestone:  5.2
Component:  Query                                |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-testing has-unit-    |     Focuses:
  tests needs-docs dev-feedback                  |
-------------------------------------------------+-------------------------

Comment (by gabrielchung1128):

 Hello, I am new to WP Core dev. I am not too sure if I am doing it
 correctly.

 I have tested the code with the range between 7 and 7 and in PHPUnit, it
 returns an error message in HTML form.

 Here is my test case:
 {{{#!php
 <?php
     public function test_tax_terms_between_same_number() {
         register_taxonomy( $tax = 'height', 'post' );

         $posts = array();

         foreach ( range( 0, 20 ) as $height ) {
             $t = self::factory()->term->create(
                 array(
                     'name'     => strval( $height ),
                     'taxonomy' => $tax,
                 )
             );

             $p = self::factory()->post->create();
             wp_set_object_terms( $p, array( $t ), $tax );
             $posts[] = $p;
         }

         $q = new WP_Query(
             array(
                 'fields'    => 'ids',
                 'tax_query' => array(
                     array(
                         'taxonomy' => $tax,
                         'operator' => 'between',
                         'field'    => 'name',
                         'terms'    => array( 7, 7 )
                     ),
                 ),
             )
         );

         $this->assertEqualSets( array_slice( $posts, 7, 0 ), $q->posts );
     }
 }}}

 Here is the error message:

 {{{
 WordPress database error You have an error in your SQL syntax; check the
 manual that corresponds to your MySQL server version for the right syntax
 to use near '' at line 1 for query SELECT  t.*, tt.* FROM wptests_terms AS
 t  INNER JOIN wptests_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE
 tt.taxonomy IN ('height') AND    made by PHPUnit\TextUI\Command::main,
 PHPUnit\TextUI\Command->run, PHPUnit\TextUI\TestRunner->doRun,
 PHPUnit\Framework\TestSuite->run, PHPUnit\Framework\TestCase->run,
 PHPUnit\Framework\TestResult->run, PHPUnit\Framework\TestCase->runBare,
 PHPUnit\Framework\TestCase->runTest,
 Tests_HelloWorld->test_tax_terms_between, WP_Query->__construct,
 WP_Query->query, WP_Query->get_posts, WP_Tax_Query->get_sql,
 WP_Tax_Query->get_sql_clauses, WP_Tax_Query->get_sql_for_query,
 WP_Tax_Query->get_sql_for_clause, WP_Tax_Query->clean_query,
 WP_Tax_Query->transform_query, WP_Term_Query->query,
 WP_Term_Query->get_terms
 F<div id="error"><p class="wpdberror"><strong>WordPress database
 error:</strong> [You have an error in your SQL syntax; check the manual
 that corresponds to your MySQL server version for the right syntax to use
 near '' at line 1]<br /><code>SELECT  t.*, tt.* FROM
 wptests_terms AS t  INNER JOIN wptests_term_taxonomy AS tt ON t.term_id =
 tt.term_id WHERE tt.taxonomy IN ('height') AND
 </code></p></div>
 }}}
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44658#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list