0

我为我的最后一个关联数组 foreach 循环提供了一个无效参数。我正在遍历不同的电子邮件地址并创建一个数组。难道我做错了什么?我应该创建一个空数组吗?

干杯!

    global $wpdb, $wpsc_variations;

    $stock_table = $wpdb->prefix . 'postmeta';
    $posts_table = $wpdb->prefix . 'posts';

    $q = 'SELECT DISTINCT post_id FROM ' . $stock_table . ' WHERE meta_key=\'' . NOTIFY_META . '\' AND meta_value=1';
    $q_assoc_arr = $wpdb->get_results($q, ARRAY_A);

    foreach($q_assoc_arr as $row) {

        $product_id = $row['post_id'];

        $product_data = get_post_custom( $product_id );
        $product_data['meta'] = maybe_unserialize( $product_data );
        foreach ( $product_data['meta'] as $meta_key => $meta_value ) {
            $product_data['meta'][$meta_key] = $meta_value[0];
        }

        if ($product_data['meta']['_wpsc_stock'] > 0) {

            foreach (get_post_meta($product_id, NOTIFY_EMAILS_META, true) as $k=>$v) {

                $emails[] = $v;

            }
4

1 回答 1

1

Your third foreach relies on the output of get_post_meta, but you're passing true as the 3rd parameter. This tells get_post_meta to return a single value as a string, not an array.

foreach expects an array to iterate over. :)

Note: This part will fail for certain, but your other instances of foreach may also fail if an array is not passed.

于 2013-05-07T19:05:08.910 回答