Home Forums Add-ons Repeater Field Filter through repeater rows by meta field value


Filter through repeater rows by meta field value

  • Is it possible to to display only certain rows of a repeater field depending on a meta key value (a number) that appears elsewhere on the page?

    I’ve got a CPT called Projects and at the bottom of the page is a text box with the selection committee names. There’s a different set of names every year, and I’m not sure how to display only certain rows of the repeater.

    The CPT archive template is set up to display projects in descending order according to the year meta key value, so 2015 projects appear, then the next page 2014 projects appear, then 2013 projects, etc.

    I’ve got the repeater working, but I have no idea how to go about filtering through the rows from there so that when 2015 projects appear, a certain repeater row displays, then when 2014 projects appear, and when it’s 2013, different repeater row displays, etc.

  • Add a field to the row identifying which year it belongs to, then add a condition in your loop checking this field against the current year being displayed.

    Or if you already know which rows you want based on other criteria, then you won’t need the extra field, just a conditional check at each iteration of your loop.

    If you need to know which row you’re currently on, you can use get_row_index() to obtain its index.

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

The topic ‘Filter through repeater rows by meta field value’ is closed to new replies.