Chris J. Lee

Dallas Drupal Developer

You are here

Using the entity field query API

Entity field query (EFQ) is prepackaged and has been used in core for Drupal 7. It's a great way to query data that has been stored by fields.

Why should one use EFQ over custom sql queries?

You can easily write your own sql queries or queries with DBTNG. However, if the schema changes somehow your code is broken and overtime it can become increasingly difficult and complex to maintain. With drupal 7, this can easily be fixed utilizing the new EFQ.

How to quickly start with EFQ

Every EFQ call requires the use of the constructor with the following:

<?php 
$query = new EntityFieldQuery();

Once you create an EntityFieldQuery object you most likely need to chain it and select an entity type:

<?php 
$query = new EntityFieldQuery()
    ->entityCondition('entity_type', 'node');

Resources

© 2017 Chris J. Lee