Skip to content

Instantly share code, notes, and snippets.

@desnudopenguino
Last active October 5, 2016 00:59
Show Gist options
  • Save desnudopenguino/1574447641c55ac3def4cf680f1c3062 to your computer and use it in GitHub Desktop.
Save desnudopenguino/1574447641c55ac3def4cf680f1c3062 to your computer and use it in GitHub Desktop.
Recursively iterate through trigger tree options
/**
* get_joined_meta - Recursively gets and builds a JSON compatible array of all of the selected trigger options to dynamically build trigger events
*
* @param string $meta_id: The string for checking the meta_id of the trigger. Default: "is null"
*
* @returns array: The compiled list of nested options for a trigger meta item in JSON format.
*/
public function get_joined_meta($meta_id = "is null")
{
/** get the global db connection */
global $wpdb;
$return_results = array();
$query="SELECT * from wp_command_triggermeta WHERE meta_id $meta_id";
$results = $wpdb->get_results($query);
if(!empty($results))
{
/** Iterate through results and build the return array */
foreach($results as $result)
{
$return_results[$result->meta_key][$result->id] = array('value' =>$result->meta_value);
/** Call this function again */
$sub_results = $this->get_joined_meta("= ". $result->id);
$keys = array_keys($sub_results);
foreach($keys as $key)
{
$return_results[$result->meta_key][$result->id][$key] = $sub_results[$key];
}
}
}
return $return_results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment