Last active
October 5, 2016 00:59
-
-
Save desnudopenguino/1574447641c55ac3def4cf680f1c3062 to your computer and use it in GitHub Desktop.
Recursively iterate through trigger tree options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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