Example: inside my function, this is the result of $wpdb in PHP 7:
wpdb Object
(
[show_errors] =>
[suppress_errors] =>
[last_error] =>
[num_queries] => 145
[num_rows] => 0
[rows_affected] => 0
[insert_id] => 0
[last_query] => SELECT * FROM wp_users WHERE user_email = '[email protected]' LIMIT 1
[last_result] => Array
etc...
So this way, I can get comment user’ ID and do my stuff, like this:
$comm_count = $wpdb->get_var('SELECT COUNT (comment_ID) FROM ' . $wpdb->comments. ' WHERE comment_author_email = "' . get_comment_author_email() . '"');
But with PHP 8, this is happening:
wpdb Object
(
[show_errors] =>
[suppress_errors] =>
[last_error] =>
[num_queries] => 132
[num_rows] => 0
[rows_affected] => 0
[insert_id] => 0
[last_query] => SELECT * FROM wp_users WHERE user_login = '#' LIMIT 1
[last_result] => Array
etc...
The query goes from user_email to user_login, any clue why?
]]>It’s my first time since a very, very long time using wordpress again and I have some issues with a function I want to create to automate a cronjob.
I’m trying to select the users i have from wp_users table and insert a few values into another table on the same database, but different table (users).
I’ve got so far with this code, but when i run it nothing happens. Not even an error.
Any suggestions are welcomed. Thank you
function wp_users_table_bind(){
global $wpdb;
$secret = mksecret();
$added = time();
$status = 'confirmed';
$result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}users" );
foreach( $result as $results ){
$name = $results['user_login'];
$passhash = $results['user_pass'];
$email = $results['user_email'];
}
$wpdb->query("INSERT INTO users (username, passhash, secret, email, status, added) VALUES ($name, $passhash, $secret, $email, $status, $added)
ON DUPLICATE KEY UPDATE
username = $name,
passhash = $passhash,
secret = $secret,
email = $email,
status = $status,
added = $added");
$wpdb->insert_id;
}
]]>add_action(‘manage_posts_extra_tablenav’, array($this, ‘add_view_search_orders’));
I’m using the add_filter(‘parse_query’, array($this, ‘parse_sku_price’)); filter to try and modify the query, BUT to achieve what I want, I need to be able to use $wpdb and write my own custom query with subqueries.
How do I go about creating a brand new query instead of modifying the existing $query object via $meta_query and $query->set( ‘meta_query’, $meta_query );
Essentially when someone filters, I want to start a whole new query using $wpdb.
Thank You
]]>I’m asking when WordPress Team plan to add into codex a function or a class to easy and securely insert data rows into wpdb
in the same way that WordPress Core add several metadata, when submitting one Post, in the table database wp_postmeta
but for its own plugin using the same process custom_postmeta
?
A developper suggested a function 7 month ago .
But I suppose a class like insert_rows
attached to wpdb{}
would make more sense?
Thanks to WordPress Team.
]]>I have a snippet that if I uncomment the wpdb->insert line (2nd to last line in the code below) doesn’t appear to run.
Does anyone have any ideas? I checked the SQL db on the CLI and my WordPress user has GRANT ALL PRIVILEGES on ‘DB’.* so I don’t think it’s a permissions issue.
if(isset($_POST['origin']) && isset($_POST['destination']) && isset($_POST['tripDate']))
{
// URL of Bing Maps REST Routes API;
$baseURL = "https://dev.virtualearth.net/REST/v1/Routes";
// Set key based on user input
$key = ""; //removed key for this post.
// construct parameter variables for Routes call
$wayPoint0 = str_ireplace(" ","%20",$_POST['origin']);
$wayPoint1 = str_ireplace(" ","%20",$_POST['destination']);
$optimize = "time";
$routePathOutput = "Points";
$distanceUnit = "mi";
$travelMode = "Driving";
$tripDate = $_POST['tripDate'];
$origin = $_POST['origin'];
$destination = $_POST['destination'];
// Construct final URL for call to Routes API
$routesURL = $baseURL."/".$travelMode."?wp.0=".$wayPoint0."&wp.1=".$wayPoint1."&optimize=".$optimize."&routePathOutput=".$routePathOutput."&distanceUnit=".$distanceUnit."&output=xml&key=".$key;
// Get output from API and convert to XML element using php_xml
$output = file_get_contents($routesURL);
$response = new SimpleXMLElement($output);
$travelDistance = $response->ResourceSets->ResourceSet->Resources->Route->TravelDistance;
$travelDistance = floatval($travelDistance);
$roundedDistance = round($travelDistance, 2);
echo "On ". $tripDate . " you travelled " . $roundedDistance ." miles from " . $origin . " to " . $destination . ".";
require_once $_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-config.php';
global $wpdb;
global $current_user; wp_get_current_user();
$currentUser = $current_user->display_name;
//$wpdb->insert('mt_trips', array('currentUser' => $currentUser, 'tripDate' => $tripDate, 'roundedDistance' => $roundedDistance, 'origin' => $origin, 'destination' => $destination]));
}
]]>Here are couple of notes for you.
Can’t reply to topics or topic’s reply section missing
—? There might be several reasons for this. When viewing a topic, the comment fields aren’t visible so it’s not possible to respond to the topic. Here are the reasons why you can’t reply to topics or topic’s reply section missing:
For more information, please check our?documentation.
Need support for?WP Discussion Board Pro: Please open a support ticket?here.
After enabling the debug log I’ve got almost 853 PHP notices at the same second (all the notices are at [07-Jul-2023 07:46:46 UTC]). These first 654 notices are:
PHP Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /var/www/html/sitename/wp-includes/class-wpdb.php on line 2019.
What I’ve tried so far: “I’ve searched for this error on stack overflow and some people said they got rid of by changing the host in the wp-config from localhost to 127.0.0.1” this solution didn’t work for me.
And the rest notices are: PHP Notice: Function wpdb was called incorrectly. wpdb must set a database connection for use with escaping. Please see Debugging in WordPress for more information. (This message was added in version 3.6.0.) in /var/www/html/7awi/wp-includes/functions.php on line 5865.
I don’t have any custom functions or custom plugins and everything is up to date
The plugin is rendered unusable at this time. I am using WordPress version 6.1
WordPress database error Table 'cm_word4ya.cm_75_connections_terms' doesn't exist for query SELECT tt.term_id, tt.term_taxonomy_id FROM cm_75_connections_terms AS t INNER JOIN cm_75_connections_term_taxonomy as tt ON tt.term_id = t.term_id WHERE t.slug = 'uncategorized' AND tt.taxonomy = 'category' ORDER BY t.term_id ASC LIMIT 1 made by require_once('wp-load.php'), require_once('/home/ws-000000015-ci/wp-config.php'), require_once('wp-settings.php'), do_action('init'), WP_Hook->do_action, WP_Hook->apply_filters, cnSettingsAPI::registerFields, apply_filters('cn_register_settings_fields'), WP_Hook->apply_filters, cnRegisterSettings::registerSettingsFields, get_option, apply_filters('default_option_cn_default_category'), WP_Hook->apply_filters, cnOptions::getDefaultCategoryID, cnTerm::exists, referer: https://anacortesfarmersmarket.org/wp-admin/admin.php?page=connections_tools
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?
]]>