Skip to content

Instantly share code, notes, and snippets.

@markhowellsmead
Last active August 9, 2023 19:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markhowellsmead/3f35a15676ec0999f4e7a772f903e592 to your computer and use it in GitHub Desktop.
Save markhowellsmead/3f35a15676ec0999f4e7a772f903e592 to your computer and use it in GitHub Desktop.
Update post template for posts matching a certain criteria
<?php
$args = [
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'any',
'meta_query' => [
[
'key' => 'hide_thumbnail',
'compare' => 'EXISTS'
]
]
];
$posts = get_posts($args);
foreach ($posts as $post) {
if ((int) get_field('hide_thumbnail', $post->ID) !== 1) {
continue;
}
update_post_meta($post->ID, '_wp_page_template', 'single-no-thumbnail');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment