簡體   English   中英

獲取所有帖子以及它們的標簽和類別

[英]Get all posts together with them tags and categories

我是wordpress的新手,已經找到了function get_posts ,它可以正常工作,但它不會檢索posts categoriestags 還有另一種功能可以做嗎,還是唯一的方法是對數據庫運行原始聯接?

編輯

這是到目前為止的內容,但是我得到了重復的行(每個標記1個,每個類別1個)

SELECT wp_posts.post_author, wp_posts.post_date, wp_posts.post_title, wp_posts.post_name, wp_terms.name, wp_users.display_name
FROM (wp_posts, wp_terms, wp_term_relationships)
INNER JOIN wp_users ON wp_users.ID = wp_posts.post_author
WHERE wp_posts.ID        = 314
AND wp_posts.ID          = wp_term_relationships.object_id
AND wp_terms.term_id     = wp_term_relationships.term_taxonomy_id
AND wp_posts.post_status = 'publish'
AND wp_posts.post_type <> 'revision'

我應該如何僅在一行中獲得類別和標簽?

謝謝。

您正在尋找類WP_Query。

該文檔在這里: https : //codex.wordpress.org/Class_Reference/WP_Query

對於類別,可以使用get_the_category(int $ id)對於標簽,可以使用wp_get_post_tags($ post_id)

供參考: https : //codex.wordpress.org/Function_Reference/wp_get_post_tags

https://developer.wordpress.org/reference/functions/get_the_category/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM