function custom_query_function() {
global $wpdb;
// Step 1: Define the SQL query
$sql_query = "SELECT * FROM {$wpdb->prefix}your_table_name WHERE column_name = 'some_value'";
// Step 2: Execute the SQL query using $wpdb object
$query_result = $wpdb->get_results($sql_query);
// Step 3: Check if the query was successful
if ($query_result) {
// Step 4: Loop through the results
foreach ($query_result as $row) {
// Step 5: Access individual columns in each row
$column_value = $row->column_name;
// Step 6: Perform actions with the retrieved data
// (e.g., echo or use data for further processing)
echo $column_value;
}
} else {
// Step 7: Handle the case where the query was not successful
echo "Query failed!";
}
}