Last active
April 7, 2016 18:51
-
-
Save badah/96f1aca440f5e696a60a to your computer and use it in GitHub Desktop.
WP - wpallimport[plugin], fill parent term in taxonomy
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
<?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; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simplify array preg_match