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

Reply To: Search doesn't show custom fields

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Search doesn't show custom fields Reply To: Search doesn't show custom fields

#30399
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Thank you for the details, it was very helpful.

After about an hour of debugging, I was finally able to find the issue. All of your configuration was perfectly fine, the results should have been there. I run a few test queries to check why the matches were missing, and I found, that the meta data is actually missing from the wp_postmeta table.
I confirmed this by running this query:

var_dump($wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE post_id = 40314"))

There was no meta data stored for that post, but clearly there should be, as it is visible on the back-end editor

So I ran a custom WP_Query with the omer_partner_code meta filter, and the returning request was very surprising:

SELECT SQL_CALC_FOUND_ROWS  wplc_posts.ID FROM wplc_posts  INNER JOIN  wplc_give_formmeta ON ( wplc_posts.ID = wplc_give_formmeta.form_id ) WHERE 1=1  AND ( 
  ( wplc_give_formmeta.meta_key = 'omer_partner_code' AND wplc_give_formmeta.meta_value = '75024998' )
) AND wplc_posts.post_type = 'give_forms' AND ...

From that, I can see that something is hooking into the original WP_Query and changing the post meta query table name to a different one. I don’t know the reason behind this, but it explains the missing results.
This is a very problematic scenario, but I added a possible fix to the functions.php file in your theme directory:

add_filter('asp_query_cpt', 'asp_custom_meta_table_on_give_form', 10, 2);
function asp_custom_meta_table_on_give_form($query, $args) {
	if ( in_array('give_forms', $args['post_type']) ) {
		$query = str_replace('wplc_postmeta', 'wplc_give_formmeta', $query);
		$query = str_replace('wplc_give_formmeta.post_id', 'wplc_give_formmeta.form_id', $query);
	}
	return $query;
}

Please note, that this may not work in all cases. The post meta should be stored in the post_meta table in the first place.