How to fetch options for a tags field from another field


So, I’ve got two selects in my panel that both should be puling from the same place. If I do it in one syntax it works, if I do it in a second syntax it doesn’t work.

So here’s the field I’m looking for…

  label: Article Categories
  type: tags
  help: These will be the available categories to tag each article with. These will also show up on the page as buttons.

And this query works…

  label: Category
  type: select
  options: query
  query: page.parents.pluck("categories", ",", true)

but this query doesn’t.

  label: Category
  type: select
  options: query
  query: site.find("abuse").pluck("categories", ",", true)

I wanted to make sure I was doing the pathing right, and site find is working right, since this will bring back a valid result of pages: query: site.find("abuse").children

But, for whatever reason, trying to query that field via site.find is bringing an error message


Everything else seems to be cool, so I can’t figure out where the error would be?

pluck() is a collection method, therefore you can use it on a collection of pages, users, files etc. and in your first example, page.parents is a collection and therefore the query works.

In your second example that doesn’t work, however, you are trying to call the pluck() method on a page object, so it cannot possibly work, because the page object doesn’t have a pluck method.

Wait, but in both cases, the thing I’m trying to pluck is the “categories” field on that page. Where that page is is the only bit being expressed differently.

Well, yes, what you are trying to pluck is the same field, but in example 1 from a collection of pages, in the second case from a single page. And that is the important difference. You can always ever use class methods with an object of the class to which the method belongs.

From a field in a single page you get an array using split()


OH! That’s totally it, you’re right!

Looks like I was misusing pluck earlier, but it just worked cause the syntax around it was screwy enough, but that didn’t work in the other case cause that’s not the syntax I should have used in the first place.

Thanks so much, @pixelijn

Just for posterity in case this helps somebody, the thing I wrote as…

page.parents.pluck("categories", ",", true)

should have actually been written as…

query: page.parent.categories.split(",")