Skip to content

fix(pick): evaluate magic tags in pick_where and pick_having - #7595

Open
faisalahammad wants to merge 3 commits into
pods-framework:release/3.4.0from
faisalahammad:fix/7406-pick-where-magic-tags
Open

fix(pick): evaluate magic tags in pick_where and pick_having#7595
faisalahammad wants to merge 3 commits into
pods-framework:release/3.4.0from
faisalahammad:fix/7406-pick-where-magic-tags

Conversation

@faisalahammad

Copy link
Copy Markdown
Contributor

Description

Magic tags like {@id}, {@post_title}, and {@name} in Relationship / Pick field pick_where and pick_having clauses were coming out blank in the resulting SQL. PodsField_Pick::get_object_data() passed the legacy positional true to pods_evaluate_tags() for these clauses, so the evaluator had no pod or item-id context. Tags then fell through to a resolver that only reads superglobals, which returns nothing for item-scoped tags, and the related-items query matched the wrong rows (or none at all).

The fix builds a tag-evaluation args array that, when an item id and a resolvable pod reference are available, instantiates (or reuses) a Pods object for the current item and passes it as the pod arg. The tag evaluator then resolves {@id}, {@post_title}, {@name}, and similar tags against the current item. For empty ids or unresolvable pod references it falls back to the previous no-pod behaviour, so existing {@get.X} usage is unaffected.

Related GitHub issue(s)

Fixes #7406

Testing instructions

  1. Create a pod, e.g. mainword, with a Relationship field pointing at a related pod, e.g. conjugation.
  2. On the relationship field, set a Where Clause like mainword.id = {@id} or main_word.post_title = {@post_title}.
  3. Open an item of the main pod and inspect the relationship field's query (for example in Query Monitor). Before the fix the resolved value is blank, e.g. mainword.id = . After the fix it contains the resolved id, e.g. mainword.id = 1051.
  4. Confirm the related-items list shows only items matching the resolved pick_where, and changes when you switch to a different main item.
  5. Regression check: {@get.X} tags (e.g. {@get.post}) still evaluate from the URL query string as before.

Screenshots / screencast

No UI changed, none to show.

Changelog text for these changes

Bug: Resolve magic tags like {@id}, {@post_title}, and {@name} in Relationship / Pick field pick_where and pick_having clauses against the current item context. #7406

PR checklist

PodsField_Pick::get_object_data() was passing the legacy positional
true to pods_evaluate_tags() for the pick_where and pick_having
clauses, so the evaluator had no pod/id context. Tags like {@id},
{@post_title}, and {@name} fell through to a superglobal-only resolver
and came out blank in the SQL, breaking the related-items filter.

Build a tag-eval args array that, when an id and a resolvable pod
reference are available, instantiates (or reuses) a Pods object for
the current item and passes it as the 'pod' arg. Falls back to the
previous no-pod behaviour for empty ids and unresolvable pod refs.

Fixes pods-framework#7406
@faisalahammad
faisalahammad changed the base branch from main to release/3.4.0 August 18, 2026 11:18
@faisalahammad

Copy link
Copy Markdown
Contributor Author

AI disclosure: this PR was written with Claude Opus 5 assistance, reviewed and tested by me.

faisalahammad and others added 2 commits August 18, 2026 21:13
Signed-off-by: Faisal Ahammad <faisalahammad24@gmail.com>
…aving

Passing a Pods object so {@id} and {@post_title} resolve also changed how
{@get.X} behaves, because pods_evaluate_tag() routes everything through
Pods::do_magic_tags() once a pod is present.

Two problems follow. Pods::process_magic_tags() only falls back to the general
resolver when PODS_SHORTCODE_ALLOW_EVALUATE_TAGS is defined and true, so with
the default configuration {@get.X} in a where clause silently resolves to
nothing where it previously read the query string. And when that constant *is*
enabled, the fallback calls pods_evaluate_tag() with no arguments, dropping the
sanitize flag the caller asked for and putting raw request data straight into a
SQL clause.

pods_tag_is_context_scoped() identifies tags that address an ambient context
(superglobals, options, transients, url helpers) and
pods_evaluate_tags_in_context() evaluates those without the pod argument, so
they reach the general resolver with sanitize intact. A field that genuinely
exists on the Pod still wins, so traversal such as {@author.display_name} is
unchanged.

Refs pods-framework#7406
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Magic tags within WHERE frequently blank

1 participant