Advertisement

05.10.2008 at 11:20AM PDT, ID: 23391908
[x]
Attachment Details

How to add Meta-Data on Plugin Activation

Asked by johnkolbert in WordPress, PHP Scripting Language, Plug Ins

Tags: WordPress, 2.5

I'm working on a plugin for WordPress and I need a way to do the following on activating the plugin:

-Pick only posts that have either "price" or "pli" set as meta data keys
-Add another meta key "isproduct" to those posts

Here's the code I'm working with, but it doesn't seem to work. Does anyone have any ideas on what to do?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
register_activation_hook(__FILE__, 'mpm_activation');
 
function mpm_activation(){
  global $post;
   $querystr = "
    SELECT wposts.* 
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE wposts.ID = wpostmeta.post_id 
    AND wpostmeta.meta_key = 'price'
    OR  wpostmeta.meta_key = 'pli'
 ";
 
 $pageposts = $wpdb->get_results($querystr, OBJECT);
 
if ($pageposts): foreach ($pageposts as $post): setup_postdata($post); 
  delete_post_meta($id, 'isproduct');
  add_post_meta($id, 'isproduct', '1');
  
  endforeach;
  endif;
}
 
 
[+][-]05.12.2008 at 04:55AM PDT, ID: 21546068

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.12.2008 at 06:25AM PDT, ID: 21546747

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.12.2008 at 07:20AM PDT, ID: 21547215

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: WordPress, PHP Scripting Language, Plug Ins
Tags: WordPress, 2.5
Sign Up Now!
Solution Provided By: Jester_48
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628