从functions.php中搜索页面元数据中的元值

I created a simple newsletter page on my WP-based website. Each time someone signs up for the newsletter his e-mail address and categories he selected are stored in metadata of that page.

Code sample from newsletter.php (it's a template):

add_post_meta(get_the_ID(), 'subscribed', array('email' => $_POST['email'], 'cats' => $_POST['chosenCats'], 'time' => get_the_time('d-m-Y | H:i')));

Here's an example of two subscriptions stored that way:

array(2) {
  [0]=>
  array(3) {
    ["email"]=>
    string(14) "agsdgeg@sdghrh"
    ["cats"]=>
    string(21) "inwestycje;targi_wyd;"
    ["time"]=>
    string(18) "23-02-2015 | 12:18"
  }
  [1]=>
  array(3) {
    ["email"]=>
    string(10) "asfas@egeg"
    ["cats"]=>
    string(31) "produkty;katalog_firm;medycyna;"
    ["time"]=>
    string(18) "23-02-2015 | 12:18"
  }
}

What do I want to do?

  1. Let's say someone subscribed for a category named "puppies".
  2. Some day I add a new post to the "puppies" category.
  3. My script launches in functions.php and looks for all subscriptions to that category in Newsletter's page metadata.
  4. It finds required subscriptions correctly and fetches e-mail addresses from each of them.
  5. It sends a notification e-mail to those people.

What is so hard about it?

The hardest part for me is figuring out how to browse through page's metadata while being in functions.php. Could you please help me with it?

Using preg_replace_callback would be an easy hack, using regex to filter meta tags.

 <?php

 $html = '<meta encoding="utf-8">';
 $metadataArray = array();

 $metadata = preg_replace_callback('/\<meta\s(.*)\>/i', function($matches)
 {
    $exp = explode($matches[1]);
    $metadataArray[$exp[0]] = str_replace('"', '', $exp[1]);
 }, $html);

Now, you'd certainly make it better than this example, but it's a quick way of filtering out data from meta tags, assuming this is what you're looking to do.