4

I need to move all playa relationships to EE relationships.

What is the best way to do this? I have not been able to find anything online explaining a process or how to approach this.

All I know is I don't want to just change the field type.

2
  • 1
    Do you have any Playa relationships which were made inside of Matrix fields? Apr 24 '14 at 12:10
  • @DerekHogue No, the Playa relationships are separate.
    – zizther
    Apr 24 '14 at 17:08
5

It's a pretty simple operation, since they are stored very similarly.

First, backup your database. Then, run this code in a PHP-enabled template:

<?php

$playa = ee()->db->query("SELECT * FROM exp_playa_relationships");
foreach($playa->result_array() as $rel)
{
    $data = array(
        'parent_id' => $rel['parent_entry_id'],
        'child_id' => $rel['child_entry_id'],
        'field_id' => $rel['parent_field_id'],
        'order' => $rel['rel_order']
    );
    ee()->db->query(
        ee()->db->insert_string('exp_relationships', $data)
    );
}

?>

Then, change your Playa fields to Relationships fields. Done.

5
  • Much simpler than I would have thought. Thanks @DerekHogue
    – zizther
    Apr 25 '14 at 20:21
  • Thanks from me also @derek-hogue for this simple solution! Question: Does this also work for EE3?
    – BNetz
    Jul 17 '16 at 10:57
  • 1
    Yup, it should. Jul 18 '16 at 0:54
  • I just tried it with an EE2-install, and it works perfectly - thanks again!
    – BNetz
    Jul 18 '16 at 21:03
  • 1
    This PHP script worked perfectly with EE 2.11.9. Had a channel with a Playa channel field associated with a Zoo Visitor member. The channel had about 2,500 entries. After using this PHP script, loading a single channel entry on the EE admin panel went from being 50 seconds to 2 seconds. Nov 13 '17 at 2:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.