Home Forums General Issues percentage in sql


percentage in sql

  • Hello,
    I used this code,but after upgrade wordpress 4.8.3, code no work. Can I help me with repair? Thank you

    	$args = array(
        'post_type' => 'product',
        'posts_per_page' => -1,
        'meta_key'=> 'product_%_date',
        'orderby' => 'meta_value_num',
        'order' => 'ASC',    
        'meta_query' => array(
    			'relation' => 'AND',
    				'key' => 'type_product',
    				'value' => $kurz_vyber,
    				'type' => 'text',
    				'compare' => 'IN'
    				'key' => 'product_%_city',
    				'value' => $product_city,
    				'type' => 'text',
    				'compare' => 'IN'
    				'key' => 'product_%_date',
    				'value' => date('Ymd'),
    				'type' => 'numeric',
    				'compare' => '>='
  • Are this percent symbols placeholder? If no and you do no more query preparation, then you should escape them with an extra percent symbol like the documentation says:

    Literals (%) as parts of the query must be properly written as %%.

    The last security update in WP 4.8.3 was a changed behaviour of esc_sql(). If you using it, here is a solution:

  • Yes, percent is placeholder. in the database I have meta_key as

  • I have the same problem since the latest WP updrade to 4.8.3.

    I use placeholder and I do not use the esc_url() function in my code and the % placeholder is being replaced with something not usable.


    This is being replaced

    	'relation' => 'OR',
    		'key' => 'charte_de_prix_contenu_%_promos_fin',
    		'value' => '',
    		'compare' => '=',
    		'key' => 'charte_de_prix_contenu_%_promos_fin',
    		'value' => date( "Ymd" ),
    		'compare' => '>=',

    with this

    meta_key = 'charte_de_prix_contenu_{47d84f1ee58a81956d53c64e8fafb5526c536eecab2be9c113fc33e7e9c86fba}_promos_fin' AND
  • The esc_url() function is included in the WP_Query Class. So if you do not use it by your own, it gets called in WP-Core. The behavoir is indeed that a single % gets replaced by a hash like {47d84f1ee58a81956d53c64e8fafb5526c536eecab2be9c113fc33e7e9c86fba}.

    Try to replace % with %d. If it doesn´t help, then paste your hole code here.

    Okay this is a know problem with ACF repeater fields. There is a discussion about it (here) and also a new ticket. You can try the workaround (here).

  • Thank you very much. You just made my day!

    This part solved my problem in Samuel Wood’s comment:

    But, you don’t want to replace the hash, you only want to replace the = with a LIKE. So, search for meta_key = ‘locations_ instead. See how I left off the % there? Now you can find it and replace it. Simple.

  • Hello,

    I have the same problem. But this solution/workaround don’t works for me. If i use the workaround i get only a blank page.

  • Thank you for that comment – I can confirm this fix works in WP 4.9.1

  • @wdj-pascal that link to the workaround by @kokers no longer contains the snippet… Must be a problem on the WordPress support forum side of things.

    Could someone post the snippet here too? I’m having this problem and I can’t find anywhere else that includes that code snippet that solved the issue.

  • I luckily found a cached version of that support thread. Looks like the support forum’s syntax highlighter library is broken or not loading. Anyway here is the snippet that @kokers provided there:

    function my_posts_where( $where ) {
        global $wpdb;
        $where = str_replace(
                  "meta_key = 'locations_%", 
                  "meta_key LIKE 'locations_%",
        return $where;
    add_filter('posts_where', 'my_posts_where');
Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.