跳到正文
gloomcheng/

ARCHIVE / 

[Drupal] 檢索本月建立的內容節點

// 取得本月第一天的 timestamp
$first_minute_of_month = mktime(0, 0, 0, date('m'), 1, date('Y'));
// 取得本月最後一天的 timestamp
$last_minute_of_month = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

$query = \Drupal::entityQuery('node')
  ->condition('status', Drupal\node\NodeInterface::PUBLISHED)
  ->condition('type', $bundle_type)
  ->condition('created', [$first_minute_of_month, $last_minute_of_month], 'BETWEEN')
  ->range(0, 10);

return $query->execute();