Advertisement

05.16.2008 at 10:18PM PDT, ID: 23410268 | Points: 500
[x]
Attachment Details

Plugin Activation

Tags: WordPress, 2.5
Ok, I hope this question isn't too intense. I've got some code (pasted below). What it SHOULD do is upong plugin activation it should get all the posts. If a meta_kety "price" or "pli" isset and !empty, it should add (or alter) a meta_key called "isproduct" by setting the value to "1". Otherwise it should set "isproduct" to "0". But I can't get it to work right. This is similar to a question that I posed previously. Do you have any ideas on how to make this work?
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' );
Start your free trial to view this solution
Question Stats
Zone: Web Development
Question Asked By: johnkolbert
Question Asked On: 05.16.2008
Participating Experts: 1
Points: 500
Views: 0
Translate:
Loading Advertisement...
05.17.2008 at 12:58AM PDT, ID: 21588340

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.17.2008 at 01:00AM PDT, ID: 21588346

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.17.2008 at 01:03AM PDT, ID: 21588352

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628