Created
August 26, 2015 20:50
-
-
Save gthayer/70d7a78c6cffe9630d95 to your computer and use it in GitHub Desktop.
Check for content, then remove from index
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
add_action( 'init', 'check_for_content', 30 ); | |
function check_for_content( $post_id ) { | |
$args = array( | |
'posts_per_page' => -1, | |
'offset' => 0, | |
'category' => '', | |
'category_name' => '', | |
'orderby' => 'date', | |
'order' => 'DESC', | |
'include' => '', | |
'exclude' => '', | |
'meta_key' => '', | |
'meta_value' => '', | |
'post_type' => 'product', | |
'post_mime_type' => '', | |
'post_parent' => '', | |
'author' => '', | |
'post_status' => 'publish', | |
'suppress_filters' => true | |
); | |
$posts = get_posts( $args ); | |
$i = 0; | |
foreach ($posts as $post) { | |
$content = $post->post_content; | |
if ( empty($content) ) { | |
update_post_meta( $post->ID, '_yoast_wpseo_meta-robots-noindex', 1 ); | |
update_post_meta( $post->ID, '_yoast_wpseo_meta-robots-nofollow', 1 ); | |
update_post_meta( $post->ID, '_yoast_wpseo_meta-robots-adv', 'none' ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment