0

In my Keystone project, I am trying to create a page that shows all posts by an author with a particular name, in this case matching the first name 'Admin'.

view.on('init', function (next) {

    var q = keystone.list('View').paginate({
        page: req.query.page || 1,
        perPage: 5,
        maxPages: 10,
        filters: {
            state: 'published',
            author.name.first: 'Admin'
        },
    })
        .sort('+publishedDate')
        .populate('author');

    q.exec(function (err, results) {

    // Use results here

    }
}

I have tried adding the following lines to the filters:

author.name.first: 'Admin'
author[name][first]: 'Admin'
author: {
  name: {
    first: 'Admin'
  }
}

But none seem to work, I'm not sure how to specify it any more than just 'author'. Any ideas?

Matt
  • 1
  • 1

1 Answers1

0

I realise this is an old post, but here you go:

I think your issue is that author isn't actually the name field type, but is simply a relationship. You need to populate this field, and THEN apply the filter. Have a read of this post, which should help you achieve what you're looking for.

As an additional comment, if you're filtering by author, it might be better to use author.name.full rather than author.name.first.

Also, note that in the mongoose query documentation here (which is what filters is going to do) there is a similar example and the name.last is inside single quotes, so you may also need to do 'author.name.full' and not just author.name.full.

Community
  • 1
  • 1
Jake Stockwin
  • 262
  • 3
  • 10