2

How can you filter entries in the CP by Author? I assumed entering something like author:tdavis (where tdavis is my username) would do it, but no results returned. I also tried substituting id for username.

1

From the Search page in the docs, it looks like you can't search by author.

It looks, on the face of it, like entries can only be searched on Title, Slug and any of your Custom Fields.

| improve this answer | |
2

For Craft 3, at least for now.

1) Make a custom plugin 2) Add event to modify the query in control panel

// Register element query prepare event
Event::on(ElementQuery::class, ElementQuery::EVENT_BEFORE_PREPARE,
    function(Event $event)  {
        if (Craft::$app->getRequest()->getIsCpRequest()) {
            if ($event->sender->elementType === 'craft\elements\Entry') {

                if(isset($_POST['criteria']['search'])&&strpos($_POST['criteria']['search'],'author')!==false)
                {
                    $email = explode(':',$_POST['criteria']['search']);
                    if(isset($email[1]))
                    {
                        $user = User::find()->email($email[1])->one();

                        if($user)
                        {

                            $event->sender->query->andWhere(['authorId'=>$user->id]);  
                            $event->sender->subQuery->andWhere(['authorId'=>$user->id]);  
                            $event->sender->search = null;
                        } 
                    }

                }
            }
        }
    }
);
  1. So when you type author:[Email] it can fetch in the CMS.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.