Support

Account

Home Forums Add-ons Repeater Field Sorting posts by subfield, sometimes multiple results per post

Helping

Sorting posts by subfield, sometimes multiple results per post

  • I have created a custom post type for ‘Rentals’, in which my client can enter their apartment buildings. Each rental property (apartment building) post has a repeater field, in which individual apartments for rent can be listed. One of the subfields is a number, reflecting the monthly rent. A rental property may have 1 available apartment or it could have 3.

    The client wants to list each available apartment by to the rent — not according to the property location. So the output might ultimately look like this:

    Property A : Apartment 2 : 500
    Property B : Apartment 1 : 650
    Property A : Apartment 1 : 675
    Property C : Apartment 3 : 700
    etc.

    I’ve tried meta queries, but it’s pretty easy to see why it’s not working; I’m sorting independent of the post itself, and that’s proving a problem. If I’d known they’d ask for it this way, I’d have done it differently — but it’s done now.
    Can someone point me in the right direction to make this work?

    I don’t mind adding in pre_get and filters if necessary, but I haven’t worked with them before — so some guidance would be very appreciated.

  • Hi @jeangoodwyn

    For something like that, I’m afraid you need to use wpdb class instead. This page should give you more idea about it: https://codex.wordpress.org/Class_Reference/wpdb.

    Keep in mind that repeater field has a unique naming system for the meta key. This page should give you more idea about it: http://www.advancedcustomfields.com/resources/repeater/#faq.

    Another approach is to create a custom post type too for the apartment too, so you can easily query it, and it’ll be flexible for further customization.

    I hope this makes sense. Thanks!

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

You must be logged in to reply to this topic.