This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Use of users custom fields in a product search

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Use of users custom fields in a product search Reply To: Use of users custom fields in a product search

#27122
Ernest MarcinkoErnest Marcinko
Keymaster

Oh, I’m sorry, I missunderstood your query.

You wanted to display the store data in the results content or title fields, and not search by that data. Since you added back-end access, I made another quick code to make it work, and already included in the functions.php file.

Now, use the store user meta fields in the advanced title and content fields like this: ||store_name||
..the new code will recognize that: https://i.imgur.com/UnFp2Ix.png

For future reference, I added this code there:

// Vendor user meta fields to advanced title and content
add_filter('asp_results', 'vendor_asp_post_content_user_meta', 10, 1);
function vendor_asp_post_content_user_meta($results) {
	$meta_fields = array(
		'_store_description',
		'store_name',
		'phone',
		'store_email',
		'wcfm_vendor_store_hours',
		'_wcfm_email_verified',
		'_wcfm_email_verified_for',
		'wcemailverified',
		'_wcfm_billing_phone',
		'payment',
		'wcfm_store_hours',
		'wcfm_shipping_policy',
		'wcfm_vacation_mode',
		'_wcfm_store_location',
		'wcfmmp_store_name'
	);
	foreach ( $results as &$r ) {
		foreach ( $meta_fields as $field ) {
			if ( strpos($r->content, '||' . $field . '||') !== false ) {
				$s = get_user_meta( get_post_field( 'post_author', $r->id ), $field, true );
				if ( !empty($s) ) {
					$r->content = str_replace('||' . $field . '||', $s, $r->content);
				} else {
					$r->content = str_replace('||' . $field . '||', '', $r->content);
				}
			}
		}
	}
    return $results;
}