Этот код позволяет искать клиента по метаданным… Я настроил searchform.php
в Wordpress для использования собственного искателя:
<h3>buscar por otro termino (direccion , telefono, ciudad , etc)</h3>
<form role="search" method="get" id="searchform" class="searchform" action="<?php echo site_url('/'); ?>">
<div class="user-form">
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
<?php
if( $_GET['s'] ) {
$search_term = sanitize_text_field( stripslashes( $_GET['s']));
// WP_User_Query arguments
$args = array (
'role' => 'customer',
'order' => 'asc',
'orderby' => 'display_name',
'meta_query' => array(
'relation' => 'or',
array(
'key' => 'nickname',
'value' => $search_term,
'compare' => 'like'
),
array(
'key' => 'last_name',
'value' => $search_term,
'compare' => 'like'
),
array(
'key' => 'billing_phone',
'value' => $search_term,
'compare' => 'like'
),
array(
'key' => 'billing_address_1',
'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->nickname . ' ' . $author_info->last_name . '</li>';
echo '<li>' . $author_info->billing_phone . '</li><br>';
echo '<li>' . $author_info->billing_address_1 . '</li><br>';
echo '<a href="'. um_user_profile_url( $author->ID ) .'">'. esc_attr( $author_info->user_nicename ) .'</a>';
//echo '<a href="'. /user( $author->ID ) .'">'. esc_attr( $author_info->user_nicename ) .'</a>';
}
echo '</ul>';
}
else {
echo 'No authors found';
}
}
?>