• Resolved bluedogranch

    (@bluedogranch)


    Hi,

    This is a rather complex question ??

    I’m using Relevanssi the overall site search, and I am also using the Paid Membership Pro plugin (which I see Relevanssi supports relevanssi_post_ok.) The PMPro plugin has its own search form, and it returns full text search results, like Relevanssi.

    In PMPro, I’ve added custom fields (i.e. user_country and user_state) for member profiles, and that added meta_key(s), i.e. user_country and user_state, stored in wp_usermeta. I can search on a word, including words whch occur the meta_key(s) (i.e. Arizona), using the default PMPro search form, and those sarch results work fine.

    But what I need to do is have dropdowns that let me select meta_key(s) to search on, like in the image https://ibb.co/GPCcZtX

    Do you have some ideas of where I would start to build a search form with And/Or drop downs for those meta_keys and meta_values?

    Would I need a search form that builds an SQL query? Or filter the results after?

    This is the default PMPro search form:

    <form role="search" method="post" class="<?php echo pmpro_get_element_class( 'pmpro_member_directory_search search-form', 'directory_search' ); ?>">
    		<label>
    			<span class="screen-reader-text"><?php _e('Search for:','pmpro-member-directory'); ?></span>
    			<input type="search" class="search-field" placeholder="<?php _e('Search Directory','pmpro-member-directory'); ?>" name="ps" value="<?php if(!empty($_REQUEST['ps'])) echo stripslashes( esc_attr($_REQUEST['ps']) );?>" title="<?php _e('Search Directory','pmpro-member-directory'); ?>" />
          <input type="hidden" name="pn" value="1" />
    			<input type="hidden" name="limit" value="<?php echo esc_attr($limit);?>" />
    		</label>
    		<input type="submit" class="search-submit" value="<?php _e('Search Members','pmpro-member-directory'); ?>">
    	</form>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Edit: Oops, I didn’t notice you were talking about wp_usermeta. None of what I said below applies to that. Since you’re searching for users and not using Relevanssi Premium, you’re working with a PMPro feature, and you should be asking this question from PMPro support. In general, what I’ve said does apply, you can add a Meta_Query to a user search, too, but you need to ask PMPro support how to modify their user search query.

    Does the PMPro search form use Relevanssi to power the search? If it does, I can help you. If it doesn’t, then you should ask these questions from the PMPro support.

    If it’s Relevanssi, there are two approaches to this. In any case, you need to add the dropdowns to the search form. You can create them with the HTML select tags; nothing complicated about that.

    Then you have two ways to handle the filtering: before and after. You can add a function on relevanssi_modify_wp_query that reads the values from the form fields and creates a Meta_Query from those values. This Meta_Query will then be applied to the Relevanssi search to restrict the search. This is the “before” approach.

    The “after” approach is to ignore the meta values at this stage and just search using the search terms. Then, with a function added to the relevanssi_hits_filter hook, you can go through the posts and remove the ones that don’t have the correct meta fields.

    Meta queries are one of slowest things you can do with the WordPress database, so the “after” approach may be faster.

    • This reply was modified 1 year, 7 months ago by Mikko Saari.
    Thread Starter bluedogranch

    (@bluedogranch)

    Thanks for the ideas! I deactivated Relevanssi and there was no change in the search results, so it appears that PMPro uses their own search. And yes, I need to figure out how to filter on meta_values in wp_usermeta. PMPro had a sample filter widget that I need to hack and add dropdowns. So I got some things figured out; thanks for your ideas.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add search dropdowns for meta_key(s)?’ is closed to new replies.