I’m maintaining 3 salon websites that all share the same stylists. The stylists are a custom post type of ‘talent’. I want to only maintain the talent on 1 site (Site A) and be able to run the same “talent” query on Site B and Site C. How to I run a query from the Site A wordpress DB from Site B on a specific template page?
Here is what I’ve got so far. I left the original query line that works in the code but’s commented out so you can see what work for calling from the current WP DB
// set up second DB
$DB_NAME2 = '...';
$DB_USER2 = '...';
$DB_PASSWORD2 = '...';
$DB_HOST2 = 'localhost';
$second_db = new wpdb($DB_USER2, $DB_PASSWORD2, $DB_NAME2, $DB_HOST2);
$location = 'locationName';
$args = "";
$args = array(
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'the-talent',
'tax_query' => array(
array (
'taxonomy' => 'location',
'field' => 'slug',
'terms' => $location,
)
),
'posts_per_page'=>-1
);
//$talent = new WP_Query( $args );
$talent = $second_db->get_results($args);
if( $talent->have_posts() ) {
while( $talent->have_posts() ) {
$talent->the_post();
$name = get_field('name');
$bio = get_field('bio');
$main_image = get_field('main_image');
// do something with variables
}// end while
}// endif