Created
January 12, 2017 10:45
-
-
Save andreilupu/f190374232ad72e21a9dce09d53d5f0f to your computer and use it in GitHub Desktop.
This code should be runned only once
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 | |
/** | |
* Delete all the duplicated `_featured` meta data | |
**/ | |
function clear_listings(){ | |
global $post; | |
$q_args = array( | |
'post_type' => 'job_listing', | |
'posts_per_page' => '-1', | |
'meta_query' => array( | |
array( | |
'key' => '_featured', | |
'compare' => 'EXISTS' | |
) | |
) | |
); | |
$query = new WP_Query($q_args); | |
while ( $query->have_posts() ) { $query->the_post(); | |
$f_meta = get_post_meta( $post->ID, '_featured', 1 ); | |
delete_post_meta( $post->ID, '_featured' ); | |
update_post_meta( $post->ID, '_featured', $f_meta ); | |
} | |
} | |
add_action('init', 'clear_listings'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment