0
エンティティフィールドクエリを使用して複数のフィールドを検索する最適な方法は何ですか? 「Project Manager」と「Developer」のカスタムフィールドを持つ「Projects」というコンテンツタイプがあり、各ユーザーのプロファイルに関連付けられているプロジェクトの一覧を表示しようとしています。エンティティフィールドクエリで複数のフィールドを検索する最も良い方法は?
これは私がこれまで持っているものです。
<?php
// Print all projects associated with this user
$profile = user_load(arg(1));
// Check database for reference to this user in pm field
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'project')
->propertyCondition('status', 1)
->fieldCondition('<insert multiple fields here..?>', 'target_id', $profile->uid, '=')
->execute();
if (!empty($result['node'])) {
$nids = array_keys($result['node']);
$nodes = node_load_multiple(array_keys($result['node']));
echo "<b>User's projects:<br></b>";
}
// display projects
foreach ($nodes as &$node) {
$targetPath = "content/";
$targetPath .= str_replace(' ', '-', $node->title);
$targetPath = 'http://'.$_SERVER['HTTP_HOST'].base_path().drupal_get_path_alias($targetPath, $path_language = '');
echo "<a href='$targetPath'>$node->title</a><br>";
}
?>
が提案していただきありがとうございます。..素晴らしいですね!しかし、私はあなたが2つの別個のエンティティIDを持つ理由を理解していません..?私は同じユーザーIDに対して2つのフィールドを比較しています... –
私はあなたが 'OR'が必要と信じています。ここで確認してください:http://drupal.stackexchange.com/questions/14499/using-or-with-entityfieldquery 2つのフィールドに基づいてユーザーを別々に読み込み、プロジェクトIDをマージして一度にロードするほうが良いかもしれません。 –