Skip to content

Instantly share code, notes, and snippets.

@fjarrett
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjarrett/be5423e0899895558d75 to your computer and use it in GitHub Desktop.
Save fjarrett/be5423e0899895558d75 to your computer and use it in GitHub Desktop.
Delete unwanted Stream Notification Rule post meta from other post types
<?php
function wp_stream_scrub_notification_rule_post_meta() {
$post_types = get_post_types( array(), 'names' );
unset( $post_types['stream_notification'] );
$args = array(
'post_type' => $post_types,
'post_status' => 'any',
'meta_key' => 'triggers',
'posts_per_page' => -1,
'no_found_rows' => true,
);
$posts = get_posts( $args );
if ( ! $posts ) {
return;
}
foreach ( $posts as $post ) {
delete_post_meta( $post->ID, 'triggers' );
delete_post_meta( $post->ID, 'groups' );
delete_post_meta( $post->ID, 'alerts' );
}
}
add_action( 'init', 'wp_stream_scrub_notification_rule_post_meta', 11 );
@fjarrett
Copy link
Author

Put this code in your theme's functions.php file to remove unwanted Stream Notification rule meta from your other post types, which was a bug reported here: xwp/stream#693

Don't leave this in your functions file, because it will run on every page load. You should remove it after you've refreshed at least once.

Also, it might take a while to refresh the first time depending on the number of posts you have. If you have 10,000+ posts or something, it won't be a good idea to run this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment