Created
June 28, 2017 22:00
-
-
Save generatepress/a5a842677e75ef968aa52ee4d9e805a3 to your computer and use it in GitHub Desktop.
Search string for {{custom_field}} and return the post meta
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
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 ) && '' !== 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