Skip to content

Instantly share code, notes, and snippets.

@esedic
Created April 25, 2025 09:35
Show Gist options
  • Save esedic/6927bb6e07c745317daeeae0425efa79 to your computer and use it in GitHub Desktop.
Save esedic/6927bb6e07c745317daeeae0425efa79 to your computer and use it in GitHub Desktop.

Revisions

  1. esedic created this gist Apr 25, 2025.
    16 changes: 16 additions & 0 deletions wp_cf_search.php
    Original 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');