简体   繁体   中英

BP search_term multiple fields

trying to search for members in my blog using multiple fields.

<?php if ( bp_has_members( "search_terms=Red Box" ) AND bp_has_members( "search_terms=Blue Box" ))  : ?>
<?php while ( bp_members() ) : bp_the_member(); ?>

…html here

<?php endwhile; ?>
<?php endif; ?>

However, if I use this code the result shows me just the 'Blue Box' Members and no both.

Any Advise?

From the BuddyPress documentation:

To search on multiple terms, put a space between each term. The search is based on 'AND', not 'OR'. So only members who have selected / entered both 'poodles' and 'carrots' will be returned.

<?php if ( bp_has_members( 'search_terms=poodles carrots' ) ) : ?>

This apparently does not work if the search terms contain spaces.

See the documentation for The Members Loop , specifically the my_custom_ids() example. You can use a similar function to pass in query terms, run a SQL statement to only get members those terms apply to, then return a string that looks like include=1,2,5,6,7 to fetch only those user IDs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM