faisca
faisca

Reputation: 11

combine users table on wordpress

I have to combine two tables on users search in wordpress: I need to add to normal search results the results from another table (with the original users table cloned structure).

I have tested:


    function get_extra_users($query) {
        $query = $query->query  . " UNION SELECT * FROM " . $wpdb->prefix ."myotheruserstable "; 
    }
    
    add_action( 'pre_user_query', 'get_extra_users' );

but nothing changes on search results

I have tested something like that too, but nothing changes:

    function get_extra_users($users) {    
    global $wpdb;
    $results = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix ."myotheruserstable ");
    $users_res = array_merge($users, $results);
    return $users_res;
}
add_filter( 'found_users_query', 'get_extra_users' ) ;

thanks for possible help

Upvotes: 0

Views: 84

Answers (1)

Mainul Hasan
Mainul Hasan

Reputation: 699

Try this way

$results = $wpdb->get_results ( "
    SELECT * 
    FROM  $wpdb->myotheruserstable
" );

If it's not working, query this way

$results = $wpdb->get_results ( "
    SELECT * 
    FROM myotheruserstable
" );

Upvotes: -1

Related Questions