/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
global $DB; $this_entry_id = "{entry_id}"; $related_field = "member_related_org"; // Query for field id of related field $rel_field_id_query = $DB->query("SELECT field_id FROM exp_weblog_fields WHERE field_name = '$related_field'"); $field_id = 'field_id_'.$rel_field_id_query->row['field_id']; // Query for rel_id values in the exp_relationships table $rel_id_query = $DB->query("SELECT rel_id FROM exp_relationships WHERE rel_child_id = '$this_entry_id'"); if($rel_id_query->num_rows > 0) { // Build query to grab all related entries based off of the rel_id values $rel_query_chunk = '('; foreach($rel_id_query->result as $row) { $rel_id = $row['rel_id']; $rel_query_chunk .= "OR exp_weblog_data.${field_id} = '$rel_id' "; } $rel_query_chunk .= ')'; '(OR ', ' )' ); '(', ')' ); $sql = " SELECT * FROM exp_weblog_titles LEFT JOIN exp_weblog_data ON exp_weblog_data.entry_id = exp_weblog_titles.entry_id WHERE $rel_query_chunk "; // Query for entry data $rel_entry_query = $DB->query($sql); if($rel_entry_query->num_rows > 0) { foreach($rel_entry_query->result as $row) { $entry_id = $row['entry_id']; $title = $row['title']; } } }