2
A
回答
5
直接的方法 - 使用直接的SQL語句SELECT
與WordPress的數據庫抽象API:
$wpdb->get_var(
$wpdb->prepare("
SELECT ID
FROM $wpdb->posts
WHERE post_title = %s
AND post_type = '%s'
", $title, $type)
);
您可以納入一個函數這個(你可以在functions.php文件的地方):
function get_post_by_title($title, $type = 'post') {
global $wpdb;
$post_id = $wpdb->get_var(
$wpdb->prepare("
SELECT ID
FROM $wpdb->posts
WHERE post_title = %s
AND post_type = '%s'
", $title, $type)
);
if(!empty($post_id)) {
return(get_post($post_id));
}
}
而且在模板中,你可以打電話給你的功能,像這樣:
$attachment = get_post_by_title('Filename', 'attachment');
echo $attachment->guid; // this is the "raw" URL
echo get_attachment_link($attachment->ID); // this is the "pretty" URL
相關問題
- 1. 使用Wordpress媒體上傳獲取圖片類型網址
- 2. 如何獲得媒體附件鏈接沒有任何鏈接在WordPress的
- 3. 如何從網站獲取mp3音頻流媒體網址?
- 4. 如何獲得我的攝像頭的流媒體RTSP/RTMP網址是什麼?
- 5. Twilio - 如何從消息列表中獲取媒體網址?
- 6. WordPress的:如何獲得網站的網址
- 7. wordpress-java API |如何獲得帖子的媒體附件鏈接?
- 8. Sitecore:如何自定義媒體網址
- 9. Umbraco從網址獲取媒體
- 10. WordPress網站上的錯誤媒體文件網址
- 11. 如何獲得沒有「default.aspx」的網址?
- 12. 媒體庫wordpress中的錯誤圖片網址
- 13. 在Sitecore中設置媒體網址
- 14. 如何獲取媒體設置wordpress
- 15. 獲得所有媒體文件wordpress的功能是什麼?
- 16. 如何獲得媒體的URI
- 17. Django中的靜態和媒體網址
- 18. 在iTunes上購買的媒體網址
- 19. 後如何獲得網址「:」
- 20. WordPress的 - 如何獲得一個具體崗位頁碼網址是什麼?
- 21. 如何在wordpress中獲得中等大小的發佈縮略圖網址?
- 22. 如何獲得Wordpress中循環外的所有現有標籤
- 23. 如何獲得通過web字體加載字體src網址
- 24. 如何獲得的圖片在媒體庫及其詳細地址
- 25. 如何從句子中獲得網址?
- 26. 如何獲得'?'和'='在一個網址?
- 27. 如何在畫廊中獲得新媒體的Uri?
- 28. 如何在Android中獲得媒體播放器的幅度?
- 29. 如何獲得在PyQt4中播放媒體的總時間?
- 30. 如何從Umbraco中的媒體選擇器獲取視頻網址
謝謝親愛的Mihai Stancu。你完成了爐排! – 2012-08-10 12:32:24