3

I am creating custom search based on entries. I need to fetch entries in custom plugin.

5

For instance like this:

$entries = Entry::find()
    ->section('sectionName')
    ->orderBy('fieldName')
    ->limit(null)
    ->all();

Have a look here in the documentation (for the code examples you can toggle Twig and PHP view for code examples): https://docs.craftcms.com/v3/dev/element-queries/entry-queries.html

Note that if you add use craft\elements\Entry; to the top of your plugin file, you can use the Entry::find() directly, you don't need the namespace prefix like in the examples in the documentation (for instance \craft\elements\Entry::find();).

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.