Advertisement
Advertisement
| 05.16.2008 at 10:18PM PDT, ID: 23410268 | Points: 500 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: |
<?php
function mpm_activate(){
add_filter('posts_join', 'mpm_activatefunc');
remove_filter('posts_join', 'mpm_activatefunc');
}
function mpm_activatefunc(){
$pageposts = $wpdb->get_results("SELECT * FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id", OBJECT);
if ($pageposts): foreach ($pageposts as $post): $post_id = $post->ID;;
$isproduct = get_post_meta($post_id, 'isproduct', $single = true); //is the "isproduct" meta-key set
$priceset = get_post_meta($post_id, 'price', $single = true); //or a price set
$pliset = get_post_meta($post_id, 'pli', $single = true);
if ((isset($priceset)) && (!empty($priceset))) {
delete_post_meta($post_id, 'isproduct');
add_post_meta($post_id, 'isproduct', '1');
}
elseif ((isset($pliset)) && (!empty($pliset))) {
delete_post_meta($post_id, 'isproduct');
add_post_meta($post_id, 'isproduct', '1');
}
else {
delete_post_meta($post_id, 'isproduct');
add_post_meta($post_id, 'isproduct', '0');
}
endforeach;
endif;
}
register_activation_hook( __FILE__, 'mpm_activate' );
|