This seems pretty simple in a template; along the lines of
if( craft.entries.authorId(10) | length ){ ... }
But how do I do that from a plugin?
craft->entries->authorId(10)
doesn't seem to exist and I've been banging my head against the docs not knowing what I'm actually looking for...
[EDIT]
I now have the following code:
$entryCriteria = craft()->elements->getCriteria(ElementType::Entry);
$entryCriteria->authorId = $existingUser->id;
$existingPages = $entryCriteria->find();
if ($existingPages) {
AutoUserEntryPlugin::log('User already exists and has a page belonging to them; aborting.', LogLevel::Info);
throw new Exception(Craft::t("You already have an account and a page created for you. Aborting. You have not been charged."));
} else {
AutoUserEntryPlugin::log('User with ID ' . $existingUser->id . ' does not seem to have a page.', LogLevel::Info);
}
But with a user I know for a fact has an Entry for which they are the author, it's returning "User with ID 1198 does not seem to have a page".
1198
has in fact authored any entries – easily done by checking for the integer1198
in theauthorId
column in thecraft_entries
database table. – Mats Mikkel Rummelhoff Jun 10 '16 at 9:12$entryCriteria->find
won't pull disabled entries by default, but you can add$entryCriteria->status = null;
to the query to also include disabled entries. – Mats Mikkel Rummelhoff Jun 10 '16 at 10:18