How can I order posts by a sub field in a repeater field of ACF

22 Views Asked by At

I have on a wordpress website 2 CPT:

  • Lessons
  • Routes

The lessons are related to routes with a Relation field from ACF with meta key "relazione_percorso".

enter image description here

The problem is that a lesson can be related to 1 ore more routes, but I need a custom position order for each routes.

For example Lesson 1 can be related to Route 1 in position 4 AND on the Route 3 in position 9.

To give a custom order of the lesson to the route, I added a Repeater field with meta key "posizione_nel_percorso".

enter image description here

Then I added 2 sub-fields:

  • A Posts Field from ACF with meta key "lista_percorsi" so I can choose the routes from the list
  • A numeric field with meta key "posizione_della_lezione_nel_percorso" where I add a number, like in the screenshot

enter image description here

Now the problem is that I cannot order the lessons in a route by "posizione_della_lezione_nel_percorso" which is the numeric field.

Save

I did something like this:

  • Show lessons WHERE meta key "relazione_percorso" LIKE current_ID (and it works)
  • Show lessons WHERE meta key "posizione_nel_percorso" and left it blank (and it works)
  • Show lessons WHERE meta key "lista_percorsi" EXISTS and it shows me 0. No posts anymore

Even if I do just ORDER BY "posizione_della_lezione_nel_percorso" ASC it doesn't show me any posts.

So basically I cannot get data from the subfields of the repeater field.

What am I missing?

PS: Using Query Builder from Jetengine

Meta query posts:

0

There are 0 best solutions below