logo

entityQuery not working return error in Drupal 10

13
December

entityQuery not working return error in Drupal 10
By: Anonymous | Published On: Wed, 12/13/2023 - 21:49

Problem:

I am using entityQuery to get Node by using following method

		$query = \Drupal::entityQuery('node');
		$query->condition('type', 'tours'); // Limit the type of node to check
		$query->condition('status',1);
		$nids = $query->execute();

but its return following error

Drupal\Core\Entity\Query\QueryException: Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck(). in Drupal\Core\Entity\Query\Sql\Query->prepare() (line 141 of /core/lib/Drupal/Core/Entity/Query/Sql/Query.php).

Solution:

I added one more line ( $query->accessCheck(); ) in my query, so now issue resolved and query working fine.

		$query = \Drupal::entityQuery('node');
		$query->condition('type', 'tours'); // Limit the type of node to check
		$query->condition('status',1);
        $query->accessCheck();
		$nids = $query->execute();

Need Help ?