【问题标题】:WordPress PHP getting each post permalinksWordPress PHP 获取每个帖子的永久链接
【发布时间】:2015-09-15 02:54:17
【问题描述】:

我想写一个函数来发送电子邮件。在邮件中,我想通过链接到 wordpress 产品页面的每个产品永久链接向客户发送他们订购的商品。

public function mailout($post_id = 106){
        global $wpdb;
        $mail = get_post_meta( $post_id, '_billing_email', true );
        $product_name = $wpdb->get_results("SELECT order_item_name FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = '$post_id' AND order_item_type = 'line_item'");
        for($i = 0; $i < count($product_name); $i++){
            $post_data[$i] = $product_name[$i]->order_item_name;
            $get_postID[$i] = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_data[$i]' ");
            $prod_url[$i] = get_post_permalink($get_postID[$i]);
        }

        $t= get_post_permalink(106);

            // $to = $mail;
            // $subject = 'Test';
            // $message = 'Thank you for purchasing! Please help us in reviewing our products.';
            // $headers[] = 'From: <donotreply@test.com>';
            // wp_mail( $to, $subject, $message, $headers );

}

我设法获得正确的帖子 ID 并使用它来获取帖子永久链接,但它似乎返回给我的都是相同的“http://localhost/domainname”循环,所有这些都指向主页。

如何更改它并使其在电子邮件中显示一些示例格式,例如以下格式,其中永久链接位于产品名称旁边?或者如果您有任何其他方法可以缩短此代码

示例结果---(产品一:http://localhost/domainname

【问题讨论】:

  • 链接到您的本地主机不会让我们看到您的页面 xD 它是本地的 - 在您的机器上。
  • 大声笑我已经可以做到了。开发阶段没有真正的数据可以在线获取实时服务器进行测试对我来说太 exp:D

标签: php wordpress email permalinks


【解决方案1】:

解决了获取每个产品页面的永久链接

public function mailout($post_id = 106){
        global $wpdb;
        $mail = get_post_meta( $post_id, '_billing_email', true );
        $product_name = $wpdb->get_results("SELECT order_item_name FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = '$post_id' AND order_item_type = 'line_item'");
        for($i = 0; $i < count($product_name); $i++){
            $post_data[$i] = $product_name[$i]->order_item_name;
            foreach ($post_data as $pd){
                $pd = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_data[$i]' ");
            }
            foreach($pd as $pdd){
                $prod_url[] = get_post_permalink($pdd);

            }

            $data_array = array('Product name' => $post_data, 'permalink' => $prod_url);
        }

        return $data_array;
        // $to = $mail;
        // $subject = 'Product Review';
        // $message = 'Thank you for purchasing! Please help us in reviewing our products.'. $data_array;
        // $headers[] = 'From: <donotreply@leminiscate.com>';
        // wp_mail( $to, $subject, $message, $headers );

    }

对于某些问题,我不知道为什么或如何将此 $prod_url 放入要发送的 $message 中。还在努力中…………

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-06
    • 2015-08-21
    • 2012-02-22
    • 1970-01-01
    • 2012-09-11
    相关资源
    最近更新 更多