Support

Account

Home Forums ACF PRO Query only against post_title in acf/fields/post_object/query Reply To: Query only against post_title in acf/fields/post_object/query

  • Yes,

    The way I would do this is first add a filter for ACF, in that filter I would add the filter than modifies the query, then after modifying the query I would remove the filter something like this.

    
    add_filter('acf/fields/post_object/query/name=your-field-name', 'modify_my_field_name_query', 10, 3);
    function modify_my_field_name_query($args, $field, $post_id) {
      //using the example from the original link I posted
      add_filter('posts_search', '__search_by_title_only', 500, 2);
      return $args
    }
    function __search_by_title_only($search, $wp_query) {
      remove_filter('posts_search', '__search_by_title_only', 500, 2);
    
      /// modify the query as shown in the other post
    
      return $search
    }