Skip to content

Instantly share code, notes, and snippets.

@badah
Last active April 7, 2016 18:51
Show Gist options
  • Save badah/96f1aca440f5e696a60a to your computer and use it in GitHub Desktop.
Save badah/96f1aca440f5e696a60a to your computer and use it in GitHub Desktop.
WP - wpallimport[plugin], fill parent term in taxonomy
<?php
/*
* WpAllImport - Fill parent term in taxonomy
* Ex:
* 1 - [match_pattern({grauacadmico[1]}, array("string1","string2"), "Parent Term")]
* 2 - [match_pattern({grauacadmico[1]}, array("string1","string2"))]
*
*/
function match_pattern($my_field, $my_array, $parent = null) {
$result = "";
foreach ($my_array as $item) {
$result += preg_match('/'.$item.'$/im', $my_field);
}
if ($parent && $result) {
return $parent;
}
if (!$parent && $result) {
return $my_field;
}
}
?>
@badah
Copy link
Author

badah commented Apr 7, 2016

Simplify array preg_match

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment