Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How do I add advanced custom fields / meta fields to Elasticsearch? [closed]

Lets break this down, Advanced Custom Fields (ACF) does save the data as custom field/post meta, I guess it seems all to obvious, but it is better to confirm it, and ElasticPress does set up custom fields automatically to include them into the search index. ElasticPress does this unless the meta data is hidden, which is the case if the custom field name is prefixed by an underscore – _.

As it is the case, that is just what ACF does, it prefixes its fields with _ making them hidden. Explained e.g. at the documentation page for update_field(), shortly summarized you read there the field_key is _ + field_name. Actually it does not or at least not for all. Not sure what the reason is, because I can’t take a look at the set-up. Anyway, the meta data gets correctly indexed, but the search doesn’t work, which will be resolved in another – link is following – question. All this is still apllying to adding additional, not automatically indexed, search data, like hidden custom fields.

In reverse having the consequence that ACF fields are not being indexed by ElasticPress. As we can see if taking a look at the EP_API class. The post meta does get included to the index like this:

'post_meta' => $this->prepare_meta( $post ),

So we take a closer look at the prepare_meta() method, where we see:

if ( ! is_protected_meta( $key ) ) {
  $prepared_meta[$key] = maybe_unserialize( $value );
}

Which confirms the suspected circumstance.

You have found the right place/hook to add the data nonetheless, being the ep_post_sync_args filter. But you did not do it correctly, especially, you are trying to append a string to an array – see above code block and source. (Note: If you had debugging enabled you would have been bugged about doing something wrong.) This won’t work of course, you need to add to the $prepared_meta array. I don’t know that much about ACF, so I leave that part out, but if you know how to get the data, then below exemplary code should make it pretty obvious to you, how to add the extra fields to the search index.

add_filter( 'ep_post_sync_args', 'wpse194785_ep_post_sync_args', 10, 2 );  
function wpse194785_ep_post_sync_args( $post_args, $post_id ) {
  $old_prepared_meta = $post_args[ 'post_meta' ];
  $additional_prepared_meta = array();
  // code to get up additional meta
  // set up data like this:
  // $additional_prepared_meta[ $key ] = array( $value );
  // note that the value is enclosed into an array
  // you can add one or multiple new elements by key => value association to the array
  // afterwards merge new and old data
  $new_prepared_meta = array_merge( $old_prepared_meta, $additional_prepared_meta );
  $post_args[ 'post_meta' ] = $new_prepared_meta;
  return $post_args;
}

Related Posts:

  1. What snippet do I need to type to show my ACF field show up on my theme?
  2. How to make search engine index PDF files? [closed]
  3. Update Multiple Post Meta for the Same Post In One call?
  4. Visual Composer vs. Advanced Custom Fields [closed]
  5. WP-PageNavi plugin doesn’t work with multiple pages of search results
  6. How can I add a custom meta value on file upload?
  7. How to get custom field image url of specific size
  8. Advanced Custom Fields query
  9. How to create Repeater fields using Advanced Custom Fields?
  10. plugin to search entire posts, blogs, forum, users [closed]
  11. How to change ID of an attachment in wp_posts and its related tables correctly?
  12. Add multiple attributes to product from php
  13. Using ACF to display data on all pages
  14. WP_Query ordering numbers as letters
  15. dynamically generating plugin syntax
  16. Search Everything plugin integration
  17. AJAX search posts and pages
  18. What is generating my meta og:description?
  19. Assign / update custom field value for all posts (How can I assign only to posts without custom field value?)
  20. Search for categories
  21. add custom filters to the event calendar plugin programatically to frontend [closed]
  22. Can you use another Profile Builder shortcodes through advanced custom fields
  23. WordPress Post Visibility Options for Frontend
  24. Bulk update all posts from plugin settings screen
  25. AJAX search as you type? [duplicate]
  26. ACF: post query, hide duplicate values [closed]
  27. Redirect to another page using contact form 7? [closed]
  28. URLs Added to ACF Repeater Field are not working
  29. Integrate Algolia to WordPress site
  30. Slashes stripped in ACF
  31. How to multiply a post to test internal search results?
  32. How to set “split_on_numerics” to false in ElasticSearch mapping using ElasticPress? (for proper SKU search in WooCommerce) [closed]
  33. Keeping and updating ACF and ACF Pro at the same time
  34. How to remove bulk actions from custom post type
  35. Adding custom meta boxes to specified custom post type
  36. Woocommerce Backend Search by Title and SKU
  37. Set Multiple Meta Values as an Array Using dispatch( ‘core/editor’ ).editPost() Call in Gutenberg/JS
  38. Search by Attachment ID
  39. Creating a search form and displaying results
  40. Preview with Custom Post Type Not Working
  41. Advanced custom fields and Slideshow gallery desn’t work together? [closed]
  42. Is it save to replace with in WordPress search form
  43. Advanced Custom Fields Plugin – Images not displaying
  44. How to validate custom fields in Quick edit/bulk edit?
  45. Why does “updated_post_meta” did not fire when uploading media other than image?
  46. WordPress search shows protected content
  47. Is there a way to make [Table Of Content] plugin while not using revision data?
  48. How to search post titles with whole words only, but not the exact word only?
  49. acf backend error handling
  50. How to add the search page link to the anchor tag?
  51. Can’t load the the canges of field groups [duplicate]
  52. Help to Create a Simple Plugin to make a post
  53. Multisite – Cloning CPT pages + content (including ACF Flexible Content) from site to site
  54. WP search box on page not finding .PDF files
  55. Redirect to a page while maintaining search query parameters without causing an infinite loop
  56. How do I change the functionality of an image slider which is part of ACF?
  57. “Enable Media Replace” plugin does not update serialized object in WPMeta
  58. Custom Field used to allow a Free Story; no longer works
  59. Get and Update Most Meta Value as an array in HTML form
  60. How to exclude a part of a page in search results
  61. multiple string replace of post’s content for large data
  62. How can I make the search bar in my wordpress site search all of the pages rather than just the blog posts?
  63. Add Custom Field to Post Pages via Plugin
  64. Returning incorrect $post->ID after installing plugin
  65. ACF Query result in a new td (echo)
  66. ACF Taxonomy search on backend (Relationship field)
  67. Get value from an input field and pass into update_meta_data as $meta_value
  68. Else If statement for ACF [closed]
  69. plugin_dir_url(__FILE__) searches parent theme in ACF extension
  70. How to make wp multisite subdomain exist search
  71. How can I remove this sidebar from my Search Results page?
  72. History of page, interval of years
  73. Same Title on two different post type with single custom taxonomy
  74. How can I make my plugin display custom post meta data on the front end?
  75. How to hook into search results template or query?
  76. WordPress Search return wrong results
  77. How to use categories in the URL with Advanced Custom Fields?
  78. Is there any simple wordpress search template that works with existing searchforms?
  79. Extend WordPress Search
  80. how to sort results by last day update at search result in plugin installer?
  81. Hide/Show panel not showing – ACF
  82. Jigoshop search taxonomy
  83. wordpress last all added get meta value by post id
  84. Dave’s WordPress Live Search only works when logged in as admin
  85. Multi-step, live updating search
  86. getting image alt text via ACF plugin in WordPress [closed]
  87. Update post meta Rest Api
  88. Can we install 3d product configurator into wordpress
  89. ACF prugin for WooCommerce Shop Page
  90. LiteSpeed cache image Optimization
  91. Advanced Custom Fields (ACF) and their Javascript API
  92. whole website redirected to another page
  93. WordPress search every time shows no search found even data exists
  94. How to Handle? vp_page Parameter in WordPress and Resolve Google Search Console Validation Issues?
  95. How to disable Yoast meta description for all pages
  96. How to add CPT in Elementor pro search template
  97. I want to create a search option for CPT using plugin. The search options should search for categories and tags
  98. PHP Fatal error: Cannot redeclare distance() when making a new block
  99. Plugin for better Backend Search? [closed]
  100. How do I apply different block supports to different parts of my custom block?
Categories plugins Tags advanced-custom-fields, plugins, post-meta, search
Creating Admin Options Page where users can make changes to a theme
Query sticky posts with thumbnails

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress