Created
April 25, 2025 09:35
-
-
Save esedic/6927bb6e07c745317daeeae0425efa79 to your computer and use it in GitHub Desktop.
Revisions
-
esedic created this gist
Apr 25, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ <?php // Source: https://wordpress.stackexchange.com/questions/414404/how-to-include-custom-fields-in-wordpress-search/414408#414408 function include_custom_field_in_search($query) { if ($query->is_search) { $query->set('meta_query', array( array( 'key' => 'release_year', 'value' => $query->query_vars['s'], 'compare' => 'LIKE' ) )); } return $query; } add_action('pre_get_posts', 'include_custom_field_in_search');