我正在關注文檔here以按類別查詢自定義帖子類型的WordPress帖子。 PHP的這個問題有答案,但是我沒有找到Python的答案。除非我錯過了某些東西,否則該功能無法按預期工作。如果我開始用下面的:如何在Python中按類別獲取自定義帖子類型的WordPress帖子
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts
from wordpress_xmlrpc.methods import posts
from wordpress_xmlrpc import WordPressTerm
wp = Client('http://www.mywebsite.info/xmlrpc.php', 'myusername', 'mypassword')
然後成功返回有問題的分類列表:
categories = wp.call(taxonomies.GetTerms('category'))
這成功返回的自定義文章類型(第10)職位列表我想查詢:
posts = wp.call(posts.GetPosts({ 'post_type': 'my-custom-post-type' }))
但是,如果我添加到以下幾點:
posts = wp.call(posts.GetPosts({ 'post_type': 'my-custom-post-type', 'terms_names': { 'category' :['my-category',]} }))
它仍然給出與沒有「條件名稱」過濾器的查詢相同的結果,就好像該附加條款完全被忽略了一樣。事實上,如果我添加不存在的類別來查詢,它使沒有返回異常/錯誤相同的結果,如:
posts = wp.call(posts.GetPosts({ 'post_type': 'my-custom-post-type', 'terms_names': { 'category' :['nonsense-word',]} }))
我也試過其他方法,如:
posts = wp.call(posts.GetPosts({ 'post_type': 'my-custom-post-type', 'terms': { 'category' :[72]} }))
...具有相同的結果。我在這裏不瞭解什麼?
有趣的是,這是我的直覺。謝謝你的提示。通過自己做過濾器,您是否建議只是針對我要查找的術語手動迭代一組檢索到的帖子?對我來說,這似乎對服務器不友好,因爲它需要檢索(在我的用例中)數百個帖子才能找到一個正確的帖子。無論哪種方式,我會考慮使用Rest API。 – NFB