Created
July 11, 2013 20:36
-
-
Save ekka21/5979014 to your computer and use it in GitHub Desktop.
Wordpress: add custom meta key to all of the post type
This file contains hidden or 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 | |
#domain.com/?run_script=1 to run this script | |
function add_my_custom_meta_key(){ | |
global $wpdb; | |
if ($_GET['run_script'] =='1' && !is_admin() ) | |
{ | |
$q = 'SELECT id from wp_posts where post_type = "MY_CUSTOM_POST_TYPE"'; | |
$ids = $wpdb->get_col($q); | |
foreach($ids as $id) | |
{ | |
$arr = array('post_id' => $id, 'meta_key' => 'MY_KEY_NAME', 'meta_value' => 'MY_VALUE'); | |
$wpdb->insert( 'wp_postmeta', $arr ); | |
} | |
} | |
print 'DONE!'; | |
} | |
add_action( 'init', 'add_my_custom_meta_key' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment