0

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)

  • 1
    It's not clear exactly what's going on in this question. Are you saying you have a grid field, with a relationship column in it? And you want to run a channel entry loop on the entries in the relationship column's parents? There is absolutely a better way to accomplish what you want I believe, but you'd help us all by editing the question and explaining not just what, but why you are going about your entry/field setup this way. – jrothafer Jul 13 at 2:38
  • Thank you, @jrothafer! Added link to EE forum topic where i explaining this issue. – shbchk Jul 14 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.