Last active
December 19, 2015 14:18
-
-
Save christopherhill/5967901 to your computer and use it in GitHub Desktop.
Drupal block of insertable code to query a content type against a field value and return matching field values. In this case, use the Smart IP module to grab the user country, and find international fields.
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 | |
// get country (requires Smart IP installed) | |
$smart_ip_session = smart_ip_session_get('smart_ip'); | |
$user_country = $smart_ip_session['location']['country']; | |
// execute a query against the international_data content type using field_location_name | |
$query = new EntityFieldQuery(); | |
$query | |
->entityCondition('entity_type', 'node') | |
->entityCondition('bundle', 'international_data') | |
->fieldCondition('field_location_name', 'value', $user_country); | |
$result = $query->execute(); | |
if (!empty($result)) { | |
$nids = array_keys($result['node']); | |
$node = node_load($nids[0]); // loads only the first result | |
$fieldValueA = $node->field_value_a[$node->language][0]['value']; | |
$fieldValueB = $node->field_value_b[$node->language][0]['value']; | |
} | |
echo '<h2>' . $fieldValueA . '</h2>'; | |
echo '<h2>' . $fieldValueB . '</h2>'' | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment