Last active
June 28, 2017 22:27
-
-
Save tomusborne/18950ce1a93d013b3c95fff1f03b44c1 to your computer and use it in GitHub Desktop.
Search string for {{custom_field}} and return the post meta
This file contains hidden or 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
if ( strpos( $content, '{{custom_field' ) !== false ) { | |
$data = preg_match_all('/{{custom_field="([^"]*)"}}/', $content, $matches); | |
foreach ( $matches[1] as $match ) { | |
if ( null !== get_post_meta( get_the_ID(), $match, true ) ) { | |
$search[] = '{{custom_field="' . $match . '"}}'; | |
$replace[] = get_post_meta( get_the_ID(), $match, true ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment