AdvancedCustomFields / AdvancedCustomFields/acf
Allow for custom search functionality in select fields
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
see : https://github.com/romainmenke/acf/pull/1
This allows for custom search functionality.
We sometimes use the select fields with dynamic data in combination with an external API. This works great!
If the API supports search it makes sense to forward $_POST['s'] to this API. The build in filter however does a very simplistic stripos validation on the label of the choices. A more sophisticated search (API-side) might include an item because it matched all terms found in $_POST['s'] but in a different order.
This change allows implementers to modify or disable the build in filter on $_POST['s'].
Examples :
// disable acf filter on $_POST['s']
add_filter(
'acf/fields/select/search/name=<my field>',
function( $include, $args, $field, $post_id ) {
return true;
},
10,
4
);
// look for individual words by splitting on spaces in $_POST['s']
add_filter(
'acf/fields/select/search',
function( $include, $args, $field, $post_id ) {
$label = $args['label'];
$s = $args['s'];
$terms = explode(" ", $s);
foreach ($terms as $term) {
if (stripos($label, $term) !== false) {
return true;
}
}
return false;
},
10,
4
);
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the select-field search handling that applies the built-in stripos filter to $_POST['s'], then review the referenced pull request for the proposed hook behavior. Done means implementers can modify or disable that filter through the documented acf/fields/select/search hooks and the supplied examples remain valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100