Tengo 3 funciones una que busca un lugares en la BD otro busca bares y me gustaría comprar en la tercera función las dos arrays de las funciones anteriores para solo sacar los comunes.
Todo el código en una sola función me funciona.
Código PHP:
function getLugar($slug){
$db = new connexio();
$lloc = $db->query("SELECT * FROM wp_terms WHERE slug ='$slug'");
$fila = $lloc->fetch_array(MYSQLI_ASSOC);
$lloc = $fila['term_id'];
$tid = $db->query("SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE term_id='$lloc'"); // torna 50 de term_taxonomy_id que es de bares
$fila2 = $tid->fetch_array(MYSQLI_ASSOC);
$tid = $fila2['term_taxonomy_id'];
$tots = $db->query("SELECT * FROM wp_term_relationships WHERE term_taxonomy_id = '$tid'");
$j = 0;
while ($fila3 = $tots->fetch_array(MYSQLI_ASSOC)){
$array1[$j] = $fila3['object_id'];
$j++;
}
return $array1;
$db->close();
}
function getBares($slug2){
$db = new connexio();
$bares = $db->query("SELECT * FROM wp_terms WHERE slug ='$slug'");
$fila = $bares->fetch_array(MYSQLI_ASSOC);
$bares = $fila['term_id'];
$tid = $db->query("SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE term_id='$bares'"); // torna 50 de term_taxonomy_id que es de bares
$fila2 = $tid->fetch_array(MYSQLI_ASSOC);
$tid = $fila2['term_taxonomy_id'];
$tots = $db->query("SELECT * FROM wp_term_relationships WHERE term_taxonomy_id = '$tid'");
$i = 0;
while ($fila3 = $tots->fetch_array(MYSQLI_ASSOC)){
$array[$i] = $fila3['object_id'];
$i++;
}
return $array;
$db->close();
}
function getComparar($slug, $slug2){
$carray = $this->getLugar($slug);
$carray2 = $this->getBares($slug2);
$result = array_intersect($carray, $carray2);
$result = implode(", ", $result);
$resultat = $db->query("SELECT post_title FROM wp_posts WHERE id IN (SELECT object_id FROM wp_term_relationships WHERE object_id IN ($result))"); //mostra el titol del bar
while ($fila4 = $resultat->fetch_array(MYSQLI_ASSOC)){
print_r($fila4['post_title']);
echo '<br/>';
}
}