First, this is confusing:
$result = $newdb->get_results("SELECT ".$column1.",".$column2." FROM members");
$columnq = $newdb->get_results("SELECT ".$column1." FROM members");
$columnq2 = $newdb->get_results("SELECT ".$column2." FROM members");
You should only need the first of those or the last two (with one alteration).
Secondly, get_results
will return an array or an object (default), so using it as you do here isn’t going to work:
'post_title' => $columnq,
post_title
does not accept an array or an object as a value.
If you want to retrieve a single string value from the database use get_var
. Then this will work:
$columnq = $newdb->get_row("SELECT ".$column1." FROM members");
$postargs = array(
'post_title' => $columnq,
'post_status' => 'draft',
'post_type' => 'bedrijf'
);
To retrieve a single row use get_row
and with proper syntax:
$result = $newdb->get_results("SELECT ".$column1.",".$column2." FROM members");
$postargs = array(
'post_title' => $result[$column1],
'post_status' => 'draft',
'post_type' => 'bedrijf'
);
But your code is still a bit confusing as you appear to be retrieving all rows from your external database/table but trying to use those rows as if they were a single row.
$columnq = $newdb->get_results("SELECT {$column1},{$column2} FROM members");
foreach ($columnq as $c) {
$postargs = array(
'post_title' => $c->column1,
'post_status' => 'draft',
'post_type' => 'bedrijf'
);
// code to insert post
}