AdvancedCustomFields / AdvancedCustomFields/acf
Options retrieval issues in get_field_objects()
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
Looks like get_field_objects() generates non optimal sql query, when as $post_id is provided option name with '_' character or ending with a digit.
For example, this call:
get_fields('option1');
generates query:
SELECT option_name, option_value
FROM wp_options
WHERE option_name LIKE 'option1_%'
OR option_name LIKE '_option1_%';
and could match some records, which belongs to 'option11', 'option12' and so on.
If I understand correctly, query should have every '_' char in params escaped here
https://github.com/AdvancedCustomFields/acf/blob/c8e181c848009aa9f6a3919ee19981fb2774f634/includes/api/api-template.php#L242-L246
to create query like this:
SELECT option_name, option_value
FROM wp_options
WHERE option_name LIKE 'option1\_%'
OR option_name LIKE '\_option1\_%';
For some cases I have several times more rows retrieved from database than it's necessary.
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 in includes/api/api-template.php at lines 242-246 and reproduce the get_fields('option1') case described in the issue. Check the generated SQL against option names such as option11 and option12; done means underscores in the parameter are treated literally so unrelated option rows are not matched.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100