I found the awesome code below that was used to detect an image in a post. I changed it a little to detect any HTML in the post and added to my functions.php
<?php
$content = $post->post_content;
$searchhtml = '~< [^>]* />~';
/*Run preg_match_all to grab all the html and save the results in $html*/
preg_match_all( $searchhtml, $content, $html );
// Check to see if we have at least 1 instance of html
$iNumberOfHTML = count($html[0]);
if ( $iNumberOfHTML > 0 ) {
add_post_meta($post-id, 'post-content', 'html', true);
}
?>
What I want is if there is HTML detected in the content of the post, to add the custom field key “post-content” and value “html”.
I’m not sure why but this just isn’t working when I try to get the key with <?php meta('post-content'); ?>
.
Any help would be greatly appreciated. Thanks!