Created
November 16, 2012 12:07
-
-
Save neotohin-snippet/4086785 to your computer and use it in GitHub Desktop.
d7:entity:field_collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Getting All nodes of a particular type | |
// In my example its node type news | |
$query = new EntityFieldQuery; | |
$query->entityCondition('entity_type', 'node') | |
->entityCondition('bundle', 'news') | |
->propertyCondition('status', 1); | |
$results = $query->execute(); | |
// Say we have a field author field_collection inside | |
// news field which have author name and source fields | |
// Lets loop through all those news entities and get those | |
// values | |
if( isset($results['node']) ) { | |
$all_news = entity_load('node', array_keys($results['node']) ); | |
foreach ($all_news as $news) { | |
$wrapper = entity_metadata_wrapper('node', $news); | |
$field_authors = field_get_items('node', $news, 'field_authors'); | |
if( $field_authors ) { | |
foreach( $field_authors as $delta => $author ) | |
print $wrapper->field_authors[ $delta ]->field_author_name->value(); | |
} | |
} | |
} | |
// Entity Field Query on FieldCondition | |
$fields = field_info_instances('message', 'follow'); | |
dsm( $fields ); | |
$query = new EntityFieldQuery; | |
$query->entityCondition('entity_type', 'message') | |
->entityCondition('bundle', 'follow') | |
->fieldCondition('field_following_user', 'target_id', 1, '=') | |
->fieldCondition('field_follow_term', 'target_id', 24, '='); | |
$results = $query->execute(); | |
dsm( $results ); | |
//$all_news = entity_load('message', array_keys($results['message']) ); | |
entity_delete_multiple( 'message', array_keys($results['message'])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment