Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on 

WordPress Get User info

I am hooking into the Wordpress advanced search.  What I am attempting to do is include a Vendors slug in the returns.  
I can get the vendors name and slug easy enough, as you see below.  However, with the  $terms = get_terms($args);  'name__like' => $name Every vendor is being returned.  
Is there a way to re-write the following so that a vendor is returned only if the name mataches?



add_filter('aws_search_results_all', 'my_aws_search_results_all', 10, 2);


function my_aws_search_results_all($results, $s) {


$vendors = get_users(array(
        'role' => 'wc_product_vendors_admin_vendor',
        'orderby' => 'user_nicename',
        'order' => 'ASC'
    ));
    if ($vendors) {
        foreach ($vendors as $vendor) {
            $name = $vendor->first_name . ' ' . $vendor->last_name;
            $fname = $vendor->first_name;
            $lname = $vendor->last_name;


            $args = array(
                'taxonomy' => array('wcpv_product_vendors'), // taxonomy name
                'orderby' => 'id',
                'order' => 'ASC',
                'hide_empty' => true,
                'fields' => 'all',
                'name__like' => $name
            );


            $terms = get_terms($args);
            foreach ($terms as $term) {
                $search = $term->slug;


                $new_result = array(
                    'name' => $name,
                    'link' => '/vendor/' . $search,
                );
                $results['tax']['user'][] = $new_result;
            }
        }
    }
    return $results;
}

Open in new window

Web DevelopmentHTMLPHPWordPress

Avatar of undefined
Last Comment
David H.H.Lee
ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo