I use Advanced Custom Fields and have a custompost-type “matches”. This post-type contains two fields “goals-made” and “goals-against”.
I want to query wordpress to show only the matches that were won. So where “goals made” > “goals-against”.
Can anyone help me get started on this one. The goal is to have a statistics page in the end.
Thx a lot for helping me out
I think something like this, but not tested, and my SQL-foo is rather weak:
This should return a list of post_ids that you can then process. But then again, it might just fail miserably.
If I was in your situation, I’d used a different approach.
Simply add an hidden meta field automatically when goals_made is updated.
E.g.
Now to retrieve the posts where
_goals-won
exists, simply run a meta query:EDIT
After some works on GhostToast answer I can give you also the right SQL query to get the same result.
Side note:
If someone write the SQL statement that handle your request,sure that SQL statement will be less performant then the simplest meta query like the first posted.Hope I didn’t understand the question wrong 🙂
As we don’t know from where you’re doing this query, simply replace
get_the_ID()
insideget_post_meta()
with the retrieved ID of the posts you want to compare against.Maybe I don’t understand the question either, because the answer is obvious to me. I assume this is for one post, so you’d have 2 custom fields, foo and bar.
So in code…