Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to perform user search with ‘OR’?


  • masterfulmistakes
    Participant

    @masterfulmistakes

    Good morning! I’m running a job site for a specific industry. The industry includes specific jobs in several categories. On my site, I’ve got a custom post type with a post for each job title and these are sorted into a custom taxonomy of job type categories.

    Users have two drop-down xprofile fields where they can declare the two job titles in which they usually work. These drop-downs are populated with the titles of the job title custom post type. So, each user can select two job titles under which they can be listed.

    I have a page which lists the job titles, sorted by their categories. Each title is linked to a BuddyPress search for users who have listed that job title on their profile. You can see the gist of that here:

    /***  List Uers by Job Title  ***/
    add_shortcode ( "list-users-by-job-links", "list_users_by_job_links_shortcode" );
    function list_users_by_job_links_shortcode() {
            echo '<div class="newspaper-3 users-by-job-list">';
            $custom_terms = get_terms('job_category');
            foreach($custom_terms as $custom_term) {
                    wp_reset_query();
                    $args = array(
                            'post_type' => 'job-title',
                            'tax_query' => array(
                                    array(
                                            'taxonomy' => 'job_category',
                                            'field' => 'slug',
                                            'terms' => $custom_term->slug,
                                    ),
                            ),
                    );
                    $query = new WP_Query($args);
                    if($query->have_posts()) {
                            echo '<h2>'.$custom_term->name.'</h2>';
                            while($query->have_posts()) : $query->the_post();
                                    echo '<h3><a href="https://obfuscated.com/members/?members_search=' . get_the_ID() . '">' . get_the_title() . '</a></h3>';
                            endwhile;
                    }
            }
            echo '</div>';
            wp_reset_postdata();
    }

    The page where I’ve used this shortcode is highly utilized and I’ve been requested to create one that will list the uers who have any job title within a certain category.

    But, I can’t find a way to do an ‘OR’ search in the members search. Is there a way to do something like this to search for users with any of the searched ids on their member profiles?
    https://obfuscated.com/members/?members_search=3147+or+3187+or+3189+or+3192

    I’m newish to PHP and WordPress, so I’m having some trouble figuring this out, but there’s another method of which I’m thinking. Loop though each custom post within a category, return a list of user_ids where each job title from that category appears, and concatenate them into a big list. Then, do a BP user query that filters by that list of user_ids.

    Would either of these be a feasible method of acheiving my goal? Any hints on where to start if the second method is the only viable method?

    Let me know if any more information would be helpful! Thanks very much for any tips or hints you can provide!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar