[wp-trac] [WordPress Trac] #42654: % sign is changed to alphanumeric combination of numbers in curly braces, by core.

WordPress Trac noreply at wordpress.org
Tue Nov 21 17:48:28 UTC 2017


#42654: % sign is changed to alphanumeric combination of numbers in curly braces,
by core.
---------------------------------+-----------------------------
 Reporter:  hostingreview        |      Owner:
     Type:  defect (bug)         |     Status:  new
 Priority:  normal               |  Milestone:  Awaiting Review
Component:  Query                |    Version:  4.9
 Severity:  normal               |   Keywords:
  Focuses:  template, multisite  |
---------------------------------+-----------------------------
 Here is the WP-Query:

 {{{#!php
 <?php
                         $category        = trim( $options['category'] );
                         $category_object = get_term_by( 'slug', $category,
 'hosting_providers_category' );
                         $category_mod    = str_replace( '-', '_',
 $category );


                         // Getting data from database
                         $args = [
                                 'posts_per_page' => $options['limit'],
                                 'post_type'      => 'hosting_providers',
                                 'orderby'        => $options['orderby'],
                                 'order'          => $options['order'],
                                 'tax_query'      => [
                                         'relation' => 'AND',
                                         [
                                                 'taxonomy' =>
 'hosting_providers_category',
                                                 'field'    => 'slug',
                                                 'terms'    => $category,
                                         ]
                                 ],
                         ];


                         if ( ! in_array( $options['orderby'], [
 'post_title' ], true ) ) {

                                 if ( $options['orderby'] === 'rank' ) {
                                         $args['orderby']    =
 'meta_value_num';
                                         $args['meta_key']   =
 $category_mod . '_rank';
                                         $args['meta_query'] = [
                                                 'key'     => $category_mod
 . '_rank',
                                                 'value'   => [ '', null, 0
 ],
                                                 'compare' => 'NOT IN',
                                                 'type'    => 'NUMERIC'
                                         ];

                                         if ( $options['rank_per_category']
 == 'yes' ) {

                                                 $args['meta_query'] = [
                                                         'relation'    =>
 'AND',
                                                         'rank_clause' => [
                                                                 'key'
 => "ranking_%_rank_in_category",
                                                                 'value'
 => 0,
                                                                 'compare'
 => '>',
                                                                 'type'
 => 'NUMERIC'
                                                         ],
                                                         [
                                                                 'key'   =>
 "ranking_%_rank_category",
                                                                 'value' =>
 $category_object->term_id
                                                         ],
                                                 ];

                                                 $args['meta_key'] =
 'ranking_%_rank_in_category';
                                                 $args['orderby']  = [
                                                         'rank_clause' =>
 'ASC'
                                                 ];
                                         }

                                 } else {
                                         $args['orderby']  = 'meta_value';
                                         $args['meta_key'] =
 $options['orderby'];
                                 }
                         }

                         if ( $options['show_alternatives_only'] == 'yes' )
 {
                                 if ( get_post_type() ==
 'hosting_providers' ) {
                                         $args['post__not_in'] = [
 get_the_ID() ];
                                         $args['orderby']      = 'rand';
                                         $args['meta_query']   = [
                                                 'relation' => 'AND',
                                                 [
                                                         'key'     =>
 $category_mod . '_rank',
                                                         'value'   => [ '',
 'NULL', 0 ],
                                                         'compare' => 'NOT
 IN',
                                                         'type'    =>
 'NUMERIC'
                                                 ],
                                                 [
                                                         'key'     =>
 $category_mod . '_rank',
                                                         'value'   => 5,
                                                         'compare' => '<=',
                                                         'type'    =>
 'NUMERIC'
                                                 ]
                                         ];

                                         if ( $options['rank_per_category']
 == 'yes' ) {

                                                 $args['meta_query'] = [
                                                         'relation'    =>
 'AND',
                                                         'rank_clause' => [
                                                                 'key'
 => "ranking_%_rank_in_category",
                                                                 'value'
 => [ '', 0 ],
                                                                 'compare'
 => 'NOT IN',
                                                                 'type'
 => 'NUMERIC'
                                                         ],
                                                         [
                                                                 'key'
 => "ranking_%_rank_in_category",
                                                                 'value'
 => 5,
                                                                 'compare'
 => '<=',
                                                                 'type'
 => 'NUMERIC'
                                                         ],
                                                         [
                                                                 'key'   =>
 "ranking_%_rank_category",
                                                                 'value' =>
 $category_object->term_id
                                                         ],
                                                 ];

                                                 $args['meta_key'] =
 'ranking_%_rank_in_category';
                                         }
                                 }
                         }


                         if ( $options['type_of_loading'] == 'preload' &&
 $options['load_more_button'] === 'on' ) {
                                 $args['posts_per_page'] = '-1';
                         }

                         $hosting_posts_query = new WP_Query( $args );
 }}}

 Here is the final request:

 {{{
 SELECT SQL_CALC_FOUND_ROWS  sjwd_20_posts.ID FROM sjwd_20_posts  LEFT JOIN
 sjwd_20_term_relationships ON (sjwd_20_posts.ID =
 sjwd_20_term_relationships.object_id) INNER JOIN sjwd_20_postmeta ON (
 sjwd_20_posts.ID = sjwd_20_postmeta.post_id )  INNER JOIN sjwd_20_postmeta
 AS mt1 ON ( sjwd_20_posts.ID = mt1.post_id )  INNER JOIN sjwd_20_postmeta
 AS mt2 ON ( sjwd_20_posts.ID = mt2.post_id ) WHERE 1=1  AND (
   sjwd_20_term_relationships.term_taxonomy_id IN (2686)
 ) AND (
   sjwd_20_postmeta.meta_key =
 'ranking_{e68324214471d5a342430315d96f93c2ce2dae368d572a9c62f70c65ed9ba7a0}_rank_in_category'
   AND
   (
     ( mt1.meta_key =
 'ranking_{e68324214471d5a342430315d96f93c2ce2dae368d572a9c62f70c65ed9ba7a0}_rank_in_category'
 AND CAST(mt1.meta_value AS SIGNED) > '0' )
     AND
     ( mt2.meta_key =
 'ranking_{e68324214471d5a342430315d96f93c2ce2dae368d572a9c62f70c65ed9ba7a0}_rank_category'
 AND mt2.meta_value = '2686' )
   )
 ) AND sjwd_20_posts.post_type = 'hosting_providers' AND
 (sjwd_20_posts.post_status = 'publish' OR sjwd_20_posts.post_status =
 'acf-disabled' OR sjwd_20_posts.post_status = 'private') GROUP BY
 sjwd_20_posts.ID ORDER BY CAST(mt1.meta_value AS SIGNED) ASC LIMIT 0, 150
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42654>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list