Home Forums Front-end Issues pre_get_posts() $query->is_search showing odd results for get_field()


pre_get_posts() $query->is_search showing odd results for get_field()

  • I have a custom pre_get_post() hook that adds meta fields to be searched for the search. This seems to interfere with how ACF does it db search.

    On my search.php page – i have get_field(‘gallery’) in the loop.

    It returns the total number of images in the gallery field type, not the array of arrays that is returned on every other normal page / post.

    var_dump( get_field(‘gallery’) ) gives me total number of arrays in the gallery field on search.php.

    var_dump( get_field(‘gallery’) ) on page/post give me array( array( ‘stuff’), array(‘sutff’) )

    Here is the debug log output.

    [01-Apr-2015 19:12:13 UTC] WordPress database error Unknown column ‘wp_postmeta.meta_key’ in ‘where clause’ for query SELECT wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = ‘acf-field’ AND ((wp_posts.post_status = ‘publish’)) AND wp_posts.post_name = ‘field_54fb32cdfe852’ OR (( wp_postmeta.meta_key = ‘basic_info_long_description_in_english’ AND ( UPPER ( wp_postmeta.meta_value ) LIKE ‘%goal%’ ) )) ORDER BY wp_posts.menu_order ASC, wp_posts.post_title ASC LIMIT 0, 1 made by require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), include(‘/themes/hipgive/search.php’), genesis, do_action(‘genesis_loop’), call_user_func_array, HIPGive_search_page_loop, include(‘/themes/hipgive/partials/project/project-summary-display-loop.php’), include(‘/themes/hipgive/partials/project/project-display-summary.php’), get_field, get_field_object, acf_get_field, _acf_get_field_by_key, get_posts, WP_Query->query, WP_Query->get_posts, QM_DB->query

    So, is there a way to tell my custom pre_get_post() hook to not interfere with ACF when it is doing it’s search?

  • This is an older request, hopefully you’ve found a solution by now. If not or if there is someone else having a similar problem, in order to know why the pre_get_posts filter is interfering you should post the code for the filter.

  • Hi John,

    Thanks for following up on this. Unfortunately this was so long ago I can’t even remember what project this was for and it seems most likely no one else has had this issue. Oh well, thanks!

  • @hyperarts, just trying to clean up some older topics :), I had a feeling that you’d either figured it out or moved on by now. I have seen some problems in the past with things interfering with ACF. Just wanted people to know that if they have similar problems that if they include code then it’ll be more likely to be looked at, as well as the fact that the forums here are getting more attention now so hopefully a question won’t go more than a year without a reply in the future.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘pre_get_posts() $query->is_search showing odd results for get_field()’ is closed to new replies.