Last active
August 9, 2022 12:58
-
-
Save lichtmetzger/43781de1b4a7bd5781c02307a78247af to your computer and use it in GitHub Desktop.
Update meta fields for CPT in WordPress if not set already
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
<?php | |
$query = new WP_Query(array( | |
'post_type' => 'company', | |
'posts_per_page' => -1 | |
)); | |
$posts = []; | |
while ($query->have_posts()) { | |
$query->the_post(); | |
$post_id = get_the_ID(); | |
$posts[] = $post_id; | |
} | |
wp_reset_query(); | |
foreach($posts as $post_id) { | |
echo $post_id; | |
if (get_post_meta($post_id, 'ctl_visibility', true) === 'true') { | |
// Do nothing | |
} else { | |
update_post_meta($post_id, 'ctl_visibility', 'false'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment