get_results()
by default returns each databse row as object, so $survey_mapping
is an array of objects. Therefore you should replace $row
with $row->surveyid
in the second query:
$dup_survey2 = absint( $wpdb->get_var(
$wpdb->prepare("SELECT surveyls_survey_id FROM oc_surveys_languagesettings WHERE surveyls_survey_id = %d", $row->surveyid)
));
and in $wpdb->delete()
:
array('surveyid' => absint($row->surveyid))
By the way, you can use a single SQL query that removes entries from oc_partner_x_survey
that have no match in oc_surveys_languagesettings
:
DELETE oc_partner_x_survey
FROM oc_partner_x_survey
LEFT JOIN oc_surveys_languagesettings ON oc_surveys_languagesettings.surveyls_survey_id = oc_partner_x_survey.surveyid
WHERE
oc_surveys_languagesettings.surveyls_survey_id IS NULL