Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Drupal 9 select node data with query conditions using entity type manager

use Drupal
odeEntityNode;

// Various entity type manager query conditions and options
// that you can use to select node data from a drupal database.
$query = Drupal::entityTypeManager()->getStorage('node')->getQuery();
// get only nodes of this content type
$query->condition('type', 'my_content_type_machine_name');
// that are "published" nodes
$query->condition('status', 1);
// and UUID equals..
$query->condition('uuid', $my_input_uuid);
// Sort by a value in a given field
$query->sort('field_my_custom_field', 'some value');
// To return a subset of the result
// This gives you only the first 10
$query->range(1, 10);
// execute query, it returns an array of matching node ids
$nids = $query->execute();

// LOAD THE RESULTING NODE OBJECTS
if (!empty($nids)) {
  $nodes = Drupal::entityTypeManager()
    ->getStorage('node')
    ->loadMultiple($nids);
}
Comment

PREVIOUS NEXT
Code Example
Php :: ’ php 
Php :: laravel gigapay get single payout 
Php :: findmany laravel 
Php :: php laravel convert blob type to string 
Php :: numeros positivos input laravel 
Php :: create product model in laravel 
Php :: find only selected columns 
Php :: cashier mollie 
Php :: slow laravel testing 
Php :: openclassroom php 
Php :: title active php 
Php :: laravel eloquent order by relationship 
Php :: prestashop show all products in category 
Php :: laravel localrole per many to many 3 foreign 
Php :: install php 7.4 fpm 
Php :: disableTimeRanges 
Php :: error import php 
Php :: devilbox make database 
Php :: laravel passport login with username 
Php :: provenienza geografica di un utente php webmaster 
Php :: laravel child relation get max value 
Php :: if data come from foreach loop and if there are same value then sum of this same value and pass it to variable in php 
Php :: number format rupiah 
Php :: vendor folder command for custom errors laravel 
Php :: Insert Data Into MySql Database Multiple Columns PHP Function 
Php :: php mailer 
Php :: convert string to int php 
Php :: php sort 
Php :: define value in php 
Php :: php invoke method 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =