Search form for Wp_user_query??!
-
Hi everyone,
I came accross the following example code
// The search term $search_term = 'Ross'; // WP_User_Query arguments $args = array ( 'role' => 'reporter', 'order' => 'ASC', 'orderby' => 'display_name', 'search' => '*' . esc_attr( $search_term ) . '*', 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'first_name', 'value' => $search_term, 'compare' => 'LIKE' ), array( 'key' => 'last_name', 'value' => $search_term, 'compare' => 'LIKE' ), array( 'key' => 'description', 'value' => $search_term , 'compare' => 'LIKE' ) ) ); // Create the WP_User_Query object $wp_user_query = new WP_User_Query( $args ); // Get the results $authors = $wp_user_query->get_results(); // Check for results if ( ! empty( $authors ) ) { echo '<ul>'; // loop through each author foreach ( $authors as $author ) { // get all the user's data $author_info = get_userdata( $author->ID ); echo '<li>' . $author_info->first_name . ' ' . $author_info->last_name . '</li>'; } echo '</ul>'; } else { echo 'No authors found'; }
I would like to use it through a search form, with the $search_term that i could setup from an input text. Any help would be greatly appreciated. TY
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Search form for Wp_user_query??!’ is closed to new replies.