Is there a same or different method/trick that I can use ?
]]>Is there a way to achieve the same or is there another approach the I might use to achieve the same possibly with an intermediate step?
Regards
Pete
]]>I am developing a plugin and I use WordPress standard (Code Sniffer)
But I get the following standard error on this code
I need to know how can I use $wpdb->prepare in the following code to pass the standard?
My code:
$get_order = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_name} WHERE order_id = %d", $order_id ) );
I get this error:
Use placeholders and $wpdb->prepare(); found interpolated variable {$table_name} at "SELECT * FROM {$table_name} WHERE order_id = %d"
“code”: “WordPress.DB.PreparedSQL.InterpolatedNotPrepared”,
“severity”: 8,
“message”: “Use placeholders and $wpdb->prepare(); found interpolated variable {$table_name} at \”SELECT * FROM {$table_name} WHERE order_id = %d\””,
“source”: “PHPCS”,
Thank you for any help
No changes have been made on my site nor any new app’s have been added. I uninstalled Updraft and downloaded again.
https://policecrimes.com/updraft/
Basicaly, it comes from easy social plugin. If i disable it, i’m not getting that anymore. Can we expect upgrade on that plugin with fix for that error?
]]>I posted the following 9 months ago:
Apparently since recent WordPress updates the plugin is producing a notice:
`PHP Notice: Function wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. Please see Debugging in WordPress for more information. (This message was added in version 3.9.0.) in /srv/http/wordpress/freehostingreviews/wp-includes/functions.php on line 5831′
This causes the display of a link: Debugging in WordPress to be displayed at the top of the page. If the plugin is deactivated the link disappears.
I never received a reply. The WordPress page for this plugin has a link:
For faster support please contact us here.
If this is clicked it opens the plugin page with an email form, but this immediately disappears if the page is scrolled.
This is the current message in the debug.log file:PHP Notice: Function wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. Please see Debugging in WordPress for more information. (This message was added in version 3.9.0.) in /home/u440861037/public_html/fwhr/wp-includes/functions.php on line 5835
Only when the Easy Social Icons plugin is activated, this message floods the debug.log file and is a nuisance when debugging other code.
Is this plugin abandonded?
I’m currently working on a project with the plugin. I faced the issue of having multiple posts with all the same data as template. In the current version it’s not possible to create templates without extending it. That’s why I’m making this Topic.
I made a solution and wanted to share it for the people who need a template, it’s working based on the option page, from there it is possible to setup a template.
add_filter('acf/prepare_field/key=field_xxxxxxxxxxxxx', function ($field) {
global $pagenow;
if($_GET['page'] !== 'general-settings' && $pagenow === 'post-new.php') {
$field['value'] = json_encode(get_field('field_option', 'option', false));
}
return $field;
});
To prepare the field, I added the prepare_field filter:
https://www.advancedcustomfields.com/resources/acf-prepare_field/
For the field key, im using the field that I want to have prefilled.
The global $pagenow
looks if the current page is a “new” post.
The $_GET['page']
checks if current admin page is not my option page.
To overwrite the empty value, it’s needed to retrieve the option page data unformatted from the database, this could be done by adding a suffix after the post_id/’option’.
After retrieving the option field you’ll have to encode the array as JSON object and overwrite the $field[‘value’] with the JSON object.
]]>I noticed that I have an issue with a search method I was using and took me a while to notice that actually preparing the LIKE input string is causing an issue. I am using the following method
$wpdb->prepare(‘%s’, ‘%blabla%’)
which gives me something like this:
‘{c4b7b43cbc69ed8d327048c2314762a3bd3d02a502d3c40a16850e2fdb0a0b0b}blabla{c4b7b43cbc69ed8d327048c2314762a3bd3d02a502d3c40a16850e2fdb0a0b0b}’
According to the documentation I am supposed to get the following: ‘%blabla%’.
Please help.
Thank you in advance.
Ivan
]]>old method:
$query = "select count(distinct(t.title)) as num_of_items from title t
WHERE t.description LIKE '%{$mysql["search"]}%' AND t.active = 1 ";
$result = mysql_query( $query, $link );
$line = mysql_fetch_array( $result, MYSQL_ASSOC );
var_dump($line);
new method:
$mysql["search"] = $wpdb->esc_like( $mysql["search"] );
$mysql["search"] = '%' . $mysql["search"] . '%';
$query = "select count(distinct(t.title)) as num_of_items from title as t
WHERE t.description LIKE %s AND t.active = 1 ";
$sql = $wpdb->prepare( $query, $mysql["search"]);
$num_of_items_arr = $wpdb->get_col($sql,0);
var_dump($num_of_items_arr);
As a side note:
Why does the above query ($sql) echo out as:
select count(distinct(t.title)) as num_of_items from title as t
WHERE t.description LIKE ‘{84e1baeb63351ba70aa6c0513d7904e1bdf6ab1481cd18e2a75f8b8acd91dc2b}saga{84e1baeb63351ba70aa6c0513d7904e1bdf6ab1481cd18e2a75f8b8acd91dc2b}’ AND t.active = 1 “
Notice: wpdb::prepare wurde fehlerhaft aufgerufen. The query does not contain the correct number of placeholders (2) for the number of arguments passed (3). Weitere Informationen: Debugging in WordPress (engl.) (Diese Meldung wurde in Version 4.8.3 hinzugefügt.) in C:\01.Websites\www.hubituning.ch\htweb\wp-includes\functions.php on line 4139
Which would in english be something like:
Notice: wpdb::prepare was called wrongfully. The query does not contain the correct number of placeholders (2) for the number of arguments passed (3). Further information: Debugging in WordPress (engl.) (This warning was added in version 4.8.3.) in C:\01.Websites\www.hubituning.ch\htweb\wp-includes\functions.php on line 4139
FYI. I have the following plugins installed:
– WPML Multilingual CMS
– WPML Media
– Share Buttons by AddThis
– Akismet Anti-Spam
I just updated them to the latest version. I also followed this recommendation and uploaded the latest version of wordpress by hand. Without success.
Anyone found a solution to this problem?
]]>