mysql
, so those direct calls won’t work. (It was never a good idea to access the database directly.)
You can leave the query variable, although it should use $wpdb->prepare
https://developer.www.ads-software.com/reference/classes/wpdb/prepare/
and then instead of mysql_query
or mysql_fetch
it needs to be the corresponding method of $wpdb
. It’s best just to use the wrapper functions that do what the code is trying to do like get_post_meta
.
$sql = $wpdb->prepare( "SELECT value FROM wp_acf_values WHERE wp_acf_values.field_id = '105' AND wp_acf_values.id = '234'" );
$result = $wpdb->query ( $sql ) or die('Content was not loaded. Please refresh your page.');
while($post = mysql_fetch_array($result)) {
$sqlTitle = $wpdb->prepare( "SELECT meta_value FROM wp_postmeta WHERE meta_id = %s", $post['value'] );
$result1 = $wpdb->query ( $sqlTitle ) or die('Content was not loaded. Please refresh your page.');
while($post1 = mysql_fetch_array($result1)) {
$spotlightTitle = $post1['meta_value'];
}
}
]]>
mysql_fetch_array
is ported over to WPDB. Seems like it uses get_results
? I realize this is a very outdated way to go about this and fully intend to modernize this but in keeping a long story short it would be very helpful to be able to sort this out within this old jumbled paradigm if possible. Is this at least on the right track or am I way off?
<?
global $wpdb;
$sql = $wpdb->prepare( "SELECT value FROM wp_acf_values WHERE wp_acf_values.field_id = '105' AND wp_acf_values.id = '234'" );
$result = $wpdb->query ( $sql ) or die('Content was not loaded.');
while($post = mysql_fetch_array($result)) {
$sqlTitle = $wpdb->prepare( "SELECT meta_value FROM wp_postmeta WHERE meta_id = %s", $post['value'] );
$result1 = $wpdb->query ( $sqlTitle ) or die('Content was not loaded.');
while($post1 = mysql_fetch_array($result1)) {
$spotlightTitle = $post1['meta_value'];
}
}
?>
]]>
mysql
functions at all, if your code has a function that begins with mysql_ or mysqli_ then you’ve used wpdb incorrectly. WPDB uses WPDB and only WPDB, and all the return values are arrays, objects, or primitives.
If you look at the docs you’ll see that none of the wpdb methods return a mysql results object, or any mysql objects at all, and none of the examples use mysql functions.
e.g.
$fivesdrafts = $wpdb->get_results( " SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'draft' AND post_author = 5 " ); foreach ( $fivesdrafts as $fivesdraft ) { echo $fivesdraft->post_title; }]]>