Home Forums ACF PRO Get all repeater fields outside the loop, but grouped?


Get all repeater fields outside the loop, but grouped?

  • I was hoping someone could point me in a direction, as my searches are bringing up things that are not applicable. My posts keep getting marked as sp@m, so excuse my clumsy censoring. I’m not sure what’s tripping it up.

    I have a CPT, “B00ks”. Within that, there is a repeater field for “Editions”. Within that, there is a select dropdown to choose a “Type”, as well as an image field for the “Cover”, and a nested repeater for links to buy them. The structure looks like below:

    ---Editions (Repeater)
    ------Type (Select/Taxonomy)
    ------Cover (Image)
    ------Purchase Links (Repeater)
    -----------Link Name (Text)
    -----------URL (URL)

    I’ve gotten all this to show up on the single-b00ks page in a super spiffy way, and I’m jazzed! I’m now looking to build an “Editions” page which should show all editions of all b00ks, grouped by “Type”. This way, all audiob00ks will appear in a row, and then all paperbacks, and then all hardbacks, so and so forth.

    Since this will be on its own page, it’ll be outside of the CPT loop. I’m not quite sure where to start with both querying the posts, plucking out ONLY the special editions, and then grouping them by tax (if applicable, as some don’t have a “Type”).

    If anyone could point me in a direction, I’d really appreciate it!

  • Hate to be a downer, but this is going to be difficult.

    Given what you have you will need to do something like this:

    I would likely have made the “Books” CPT and then used child posts to create the “Editions” and separated the custom fields between parent/child posts based on what they applied to. This way you could show child posts on the parent post CPT and you could query all child posts by the “Type” taxonomy page (template: archive-{$taxonomy}.php} to show lists of books for each type.

  • I take that back, given what you have there isn’t any way to create page that lists books by “Edition” unless you query all books and then loop over the repeater for every book to see if it has that edition.

  • Ah, well darn, that bums me out! I just got everything how I wanted it on the single-book pages lol.

    I’m trying to avoid having 20 different posts for the same book, just a new edition (there are also special editions and foreign translations), as that’s pretty weighty for essentially 4 fields and will significantly clutter things up.

    I’ll try to think on it. I thank you sincerely for the advice!

  • I wonder, could I maybe reverse this and have an Editions CPT that lists, for example, all audiobooks in one post, and link them to the Book CPT they belong to? Would that be possible to pass to its own page?

  • Yes, you could do it that way but you would need to have a relationship field on each “Edition” post to connect to all the “Books”. If you don’t then you’d still be looking at doing a query of all the books and looping to find the right ones.

    The main issue is that you have the “Edition” type in a repeater and it is difficult to search by a repeater sub field, there is some documentation about it on this page If you do this the performance will not be good.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.