Creating a Pods relationship programmatically produces error in Advanced Custom Fields

1.9k Views Asked by At

I'm trying to create a pods relationship using the following code:

$data = array(
    "pod_id" => esc_attr(strip_tags($_POST['customMetaAutorID'])),
    "field_id" => 1073,
    "item_id" => $post_id,
    "related_item_id" => $_POST["customMetaAutorID"],
    "related_pod_id" => 0,
    "related_field_id" => 0,
    "weight" => 0
 );
 $wpdb->insert("wp_podsrel", $data);

The row gets added to the table, how ever, after a few page refreshes I start getting the error:

Strict Standards: Declaration of acf_taxonomy_field_walker::start_el() should be compatible with Walker::start_el(&$output, $object, $depth = 0, $args = Array, $current_object_id = 0)

This means that all I have is the white screen of death and the only thing I can do is to restore the database.

What's the way to add a pods relationship field value and not breaking everything else?

1

There are 1 best solutions below

2
On BEST ANSWER

Found out the answer myself.

Turns out each pod item has an add_to function wich adds values to related fields given the field name (much more convenient than harcoding the field ID)

The code I ended up using is this:

$postPod->add_to("field_name", $related_element_id);