Skip to content

Instantly share code, notes, and snippets.

@nikitasinelnikov
Created July 22, 2021 16:04
Show Gist options
  • Save nikitasinelnikov/7eea6e406aa947b670f9ab66048cdcd6 to your computer and use it in GitHub Desktop.
Save nikitasinelnikov/7eea6e406aa947b670f9ab66048cdcd6 to your computer and use it in GitHub Desktop.
Ultimate Member 2.2.0. Update `Hide from queries` meta for posts and terms
// run this function only once for bulk uncheck `Hide from queries` option for restricted pages, posts
function um_update_post_restrictions() {
global $wpdb;
$posts = $wpdb->get_results("SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key = 'um_content_restriction'", ARRAY_A );
foreach ( $posts as $post ) {
$meta_value = maybe_unserialize( $post['meta_value'] );
$meta_value['_um_access_hide_from_queries'] = false;
update_post_meta( $post['post_id'], 'um_content_restriction', $meta_value );
}
$terms = $wpdb->get_results("SELECT term_id, meta_value FROM {$wpdb->termmeta} WHERE meta_key = 'um_content_restriction'", ARRAY_A );
foreach ( $terms as $term ) {
$meta_value = maybe_unserialize( $term['meta_value'] );
$meta_value['_um_access_hide_from_queries'] = false;
update_term_meta( $term['term_id'], 'um_content_restriction', $meta_value );
}
}
add_action( 'wp_loaded', 'um_update_post_restrictions' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment