Programmatically adding a pod with a relationship field
-
I’m developing a web site of walks, and have got a Walks custom post type pod to represent each walk. One of the fields is walk_grade which represents the grade of difficulty, and I’ve used a Field Type of Relationship related to a Grades custom taxonomy pod to represent that.
I need to add the walks pod records programmatically to implement the migration from a previous system, and that’s where I’ve been having difficulties with setting the walk_grade relationship field.
I’ve tried:
$pod = pods('walk'); $data = array( 'post_title' => 'Test walk title', 'post_content' => 'Short walk test description text', 'town' => 'Townsville', 'walk_grade' => 'Easy' // tried it with and without this line ); $id = $pod->add($data); // this creates the pod with the title, content and town, but not grade $id = $pod->add_to('walk_grade', 'Easy'); // this doesn't workInstead of the add_to call updating the walk with the grade of difficulty I find that it’s created a new walks pod which is basically empty (and I get back a new $id).
Could someone please point me in the right direction?
Thanks,
Robbie
The topic ‘Programmatically adding a pod with a relationship field’ is closed to new replies.