2017-04-11 33 views
1

好了,所以我用此Javascript QR代碼生成器:https://github.com/davidshimjs/qrcodejsJavaScript的QR碼PHP的元網址

找出你能夠通過包括此頁面上有一個字符串輸出盒。

<div id="qrcode"></div> 
    <script type="text/javascript"> 
    new QRCode(document.getElementById("qrcode"), 
    "http://example.com"); 
    </script> 

我需要這有一個前綴開頭,如「https://saucyfreds.com/point-adder/」,然後我需要一個WordPress用戶meta值添加到這個網址的結尾的網址。

如何獲取WordPress UserMeta值並將其添加到此URL中?

+0

可以提供例如所需的輸出 – Jpsh

+0

這將是由一種叫做自動登錄鏈接插件生成的字符串。 https://wordpress.org/plugins/autologin-links/所以輸出將是「https://saucyfreds.com/point-adder/?autologin_code=wJFdnmmJgbtdHOnydWuEi7CWdlDyBP」 – WordPressFreddie

回答

0

與插件「插入PHP」組合使用上述pomaaa的例子我能想出此解決方案!

<div id="qrcode"></div> 
    <script type="text/javascript"> 
    new QRCode(document.getElementById("qrcode"), 
    "https://saucyfreds.com/point-adder/?autologin_code=[insert_php]       
    echo get_user_meta(get_current_user_id(), pkg_autologin_code, 
    true); [/insert_php]"); 
    </script> 
0

你有該用戶的ID嗎?如果是這樣,你可以做這樣的:

<div id="qrcode"></div> 
<script type="text/javascript"> 
new QRCode(document.getElementById("qrcode"), 
"https://saucyfreds.com/point-adder/<?php echo get_user_meta($user_id, $key, true); ?>"); 
</script> 

你將不得不與 你要顯示的wp_usermeta表meta_key您的用戶和$鑰匙的ID來代替$ USER_ID。

如果要顯示它您可以使用get_current_user_id當前用戶()這樣的:

<div id="qrcode"></div> 
<script type="text/javascript"> 
new QRCode(document.getElementById("qrcode"), 
"https://saucyfreds.com/point-adder/<?php echo get_user_meta(get_current_user_id(), $key, true); ?>"); 
</script> 
+0

這可以工作,但我需要id來更新到每個查看此qr代碼的用戶的id?那可能嗎? – WordPressFreddie

+0

是的,你可以,我已經更新了代碼。 – pomaaa