Since i can not retrieve {parents} from grid field, i am trying to find simplest workaround.
This works great:
{exp:channel:entries channel='channel-one' entry_id='
<?php
$servername = 'blabla';
$username = 'blabla';
$password = 'blabla';
$dbname = 'blabla';
// Create connection
$db = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$db) {
die("Connection failed: " . mysqli_connect_error());
}
$url_pieces = explode("/", $_SERVER['REQUEST_URI']);
$sql = 'SELECT parent_id FROM exp_relationships WHERE child_id = '.$url_pieces[2].'';
$result = mysqli_query($db, $sql);
while($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
echo $row['0']."|";
}
?>
' disable='categories|member_data|pagination|category_fields'}
This works great also and produces little more total_queries:
{exp:channel:entries channel='channel-one' entry_id='
<?php
$pieces = explode("/", $_SERVER['REQUEST_URI']);
$sql = 'SELECT parent_id FROM exp_relationships WHERE child_id = '.$pieces[2].'';
$query = ee()->db->query($sql);
if ($query->num_rows() > 0)
{
foreach($query->result_array() as $row)
{
echo $row['parent_id']."|";
}
}
?>
' disable='categories|member_data|pagination|category_fields'}
But i can not get same result when i’m trying to use {exp:query}, it shows me nothing or error.
Here is what i’ve tried:
{parents_ids} Template Partial content:
{exp:query sql="SELECT parent_id FROM exp_relationships WHERE child_id = '{last_segment}'" backspace="1"}{parent_id}|{/exp:query}
Tempate code:
{exp:channel:entries channel='channel-one' entry_id='{parents_ids}' disable='categories|member_data|pagination|category_fields'}
This returns nothing.
Is there anyway to do what i am trying to do without php in templates?
(ExpressionEngine® CMS 5.3.2, PHP 7.3.15)
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.