Home › Forums › General Issues › 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',
array(
'key' => 'type_product',
'value' => $kurz_vyber,
'type' => 'text',
'compare' => 'IN'
)
,
array(
'key' => 'product_%_city',
'value' => $product_city,
'type' => 'text',
'compare' => 'IN'
)
,
array(
'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:
https://make.wordpress.org/core/2017/10/31/changed-behaviour-of-esc_sql-in-wordpress-4-8-3/
Yes, percent is placeholder. in the database I have meta_key as
product_0_city
product_1_city
product_2_city
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.
Example:
This is being replaced
array(
'relation' => 'OR',
array(
'key' => 'charte_de_prix_contenu_%_promos_fin',
'value' => '',
'compare' => '=',
),
array(
'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.
[EDIT]
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_%",
$wpdb->remove_placeholder_escape($where)
);
return $where;
}
add_filter('posts_where', 'my_posts_where');
The topic ‘percentage in sql’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.