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. Unable to check if plugin is active
  3. How to get current post ID in Contact Form 7 wpcf7_before_send_mail hook action
  4. How to make search engine index PDF files? [closed]
  5. Using Advanced Custom Fields with WordPress and Lightbox
  6. How to override normal WordPress search in Buddypress? [closed]
  7. Search and replace text across all posts
  8. Update Multiple Post Meta for the Same Post In One call?
  9. How to store ACF custom fields data in a custom table
  10. Generate Advanced Custom Fields box in custom admin menu page
  11. How would implement StackExchange ‘Questions with similar titles’ for the FAQ on my wordpress site
  12. Edit Imported advanced Custom Fields from wordpress Dashboard
  13. dynamic page not indexed
  14. How to get posts by content?
  15. Visual Composer vs. Advanced Custom Fields [closed]
  16. ACF for audio url in wordpress audio shortcode
  17. Can you use another Profile Builder shortcodes through advanced custom fields
  18. How can I change the meta_key for a particular piece of information?
  19. WordPress Post Visibility Options for Frontend
  20. dirname( __FILE__) returning wrong directory inside plugin
  21. Bulk update all posts from plugin settings screen
  22. AJAX search as you type? [duplicate]
  23. WooCommerce search products between price range using WP_Query
  24. ACF: post query, hide duplicate values [closed]
  25. Redirect to another page using contact form 7? [closed]
  26. Paid Membership Pro with ACF [closed]
  27. ACF only showing up in Homepage but doesn’t appears in all pages
  28. Meta box losing its value when scheduled post is published
  29. Advanced Custom Fields – Disable Users to Edit Custom Fields
  30. How to insert multiple postmeta values with one query?
  31. Mass SQL WordPress Meta Key deletion
  32. Using ACF default value to autoincrement a number field
  33. Send admin an email when a user’s search has no results
  34. URLs Added to ACF Repeater Field are not working
  35. Advanced Custom Fields – Get value in other plugin file [closed]
  36. Integrate Algolia to WordPress site
  37. Date format – Meta Box plugin
  38. Slashes stripped in ACF
  39. get meta value from database by post id
  40. How to multiply a post to test internal search results?
  41. Remove Advanced Custom Fields plugin for client?
  42. Adding class to last list item? Not WP generated
  43. How to set “split_on_numerics” to false in ElasticSearch mapping using ElasticPress? (for proper SKU search in WooCommerce) [closed]
  44. Keeping and updating ACF and ACF Pro at the same time
  45. How to remove bulk actions from custom post type
  46. Adding custom meta boxes to specified custom post type
  47. How to select a paragraph other than the 1st to be the post’s excerpt?
  48. How do we update a custom file upload field with the Advanced Custom Field plugin?
  49. Woocommerce Backend Search by Title and SKU
  50. Set Multiple Meta Values as an Array Using dispatch( ‘core/editor’ ).editPost() Call in Gutenberg/JS
  51. How can I concatenate variables to search results title? [closed]
  52. Advanced Custom Fields (acf) – Filter Relationship by Taxonomies not Post Type
  53. Search and Filter Plugin – How to disable redirection
  54. WordPress Multi-Step Product Search
  55. Search by Attachment ID
  56. ACF – How to set the menu order for the relationship field
  57. Custom search search does not work?
  58. Conditional custom redirect
  59. Creating a search form and displaying results
  60. Preview with Custom Post Type Not Working
  61. Remember the Meta Value With Radio Buttons
  62. How to display a number of posts based on a Advanced Custom Field (ACF)
  63. Translation to ACF relationship field
  64. How to get the get the select values created by ACF plugin in wordpress
  65. Advanced custom fields and Slideshow gallery desn’t work together? [closed]
  66. Is it save to replace with in WordPress search form
  67. Advanced Custom Fields Plugin – Images not displaying
  68. Link Posts to External URL
  69. How to create repeater field manually, without plugin (ACF Pro)?
  70. How to validate custom fields in Quick edit/bulk edit?
  71. Why does “updated_post_meta” did not fire when uploading media other than image?
  72. WordPress search shows protected content
  73. Is there a way to make [Table Of Content] plugin while not using revision data?
  74. Best approach to make all tags searchable by the wordpress search function
  75. Replace the_content with ACF Flexible Content via function
  76. How to search post titles with whole words only, but not the exact word only?
  77. acf backend error handling
  78. RSS feeds for specific topics
  79. How to add the search page link to the anchor tag?
  80. Setting Author on CPT
  81. Can’t load the the canges of field groups [duplicate]
  82. Help to Create a Simple Plugin to make a post
  83. WC Fix Attributes – ‘Add New’ Not Searchable/Delayed
  84. Multisite – Cloning CPT pages + content (including ACF Flexible Content) from site to site
  85. get_post_meta shortcode returns empty field
  86. Add an action based on custom post meta field
  87. How to hide an option from dropdown in filter module
  88. ACF checkbox return format based on page
  89. WP search box on page not finding .PDF files
  90. how to auto random increment for post view
  91. custom fields not displaying on wordpress site
  92. Redirect to a page while maintaining search query parameters without causing an infinite loop
  93. ACF Fields are not showing up on Homepage
  94. Search results to point to specific section?
  95. How to securely controlling data without keeping it in postmeta?
  96. Why Custom fields description is not working WordPress Version 5.4.2?
  97. Images are broken in Wysiwyg Editor – ACF backend
  98. How do I apply different block supports to different parts of my custom block?
  99. Draft standard post by ACF Data picker
  100. Query Custom Post Types on Available Dates
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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