显示来自 x cat 和 y tag 的帖子

发布于 2024-08-19 06:05:35 字数 214 浏览 7 评论 0原文

是否可以获取与类别 x“AND”标签 y 匹配的帖子?

阅读文档,似乎您可以这样做:

query_posts('tag=bread,baking');

或者

query_posts('cat=2,6,17,38');

...是否可以同时使用 cat 和 tag?

Is it possible to fetch posts matching categorie x "AND" tag y?

Read the docs, it seems you can do:

query_posts('tag=bread,baking');

or

query_posts('cat=2,6,17,38');

... is it possible to use both cat and tag simultaneously?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

身边 2024-08-26 06:05:35

我不是 WordPress 专家,但我通过查找该函数看到的是,您应该能够使用此表示法以便同时查询两者。

query_posts('tag=bread,baking&cat=2,6,17,38');

I am not a Wordpress expert, but what I see from looking up that function, is that you should be able to use this notation in order to query against both at the same time.

query_posts('tag=bread,baking&cat=2,6,17,38');
你的往事 2024-08-26 06:05:35

这是取自我之前回答过的另一个问题,它已经过测试并且工作正常,所以我们开始吧。您可以使用以下方法手动查询数据库:

SELECT *  
FROM wp_term_taxonomy AS cat_term_taxonomy 
INNER JOIN wp_terms AS cat_terms ON cat_term_taxonomy.term_id = cat_terms.term_id 
INNER JOIN wp_term_relationships AS cat_term_relationships ON cat_term_taxonomy.term_taxonomy_id = cat_term_relationships.term_taxonomy_id 
INNER JOIN wp_posts AS cat_posts ON cat_term_relationships.object_id = cat_posts.ID 
WHERE cat_posts.post_status = 'publish' AND cat_posts.post_type = 'post' AND cat_terms.term_id = '13,26,45,89,117'

您要做的就是为要查找的每个标签/类别提供 termID。

我不确定它是否有效,但从技术上讲,标签和类别位于同一个表中。所以,我认为如果你在 cat= 参数中提供 tagID 它可能会起作用,我目前没有机会测试它,但绝对值得一试。

This is taken from another question that I had answered previously and it was tested and worked properly, so here we go. You can manually query your database using the following:

SELECT *  
FROM wp_term_taxonomy AS cat_term_taxonomy 
INNER JOIN wp_terms AS cat_terms ON cat_term_taxonomy.term_id = cat_terms.term_id 
INNER JOIN wp_term_relationships AS cat_term_relationships ON cat_term_taxonomy.term_taxonomy_id = cat_term_relationships.term_taxonomy_id 
INNER JOIN wp_posts AS cat_posts ON cat_term_relationships.object_id = cat_posts.ID 
WHERE cat_posts.post_status = 'publish' AND cat_posts.post_type = 'post' AND cat_terms.term_id = '13,26,45,89,117'

All that you would do is that you would provide the termID for each of the tags/categories that you want to find.

I'm not sure if it would work or not, but technically tags and categories are within the same table. So, I would think that if you provide the tagID within the cat= parameter it might work, I don't have a chance to test it currently, but definitely worth a try.

兮颜 2024-08-26 06:05:35

是的,你可以。我最近不得不在我的 WordPress 日志页面上显示所有未来的帖子,我只是使用了:

query_posts($query_string . '&post_status=future,publish');

它工作得完美无缺。

Yes, you can. I recently had to show all future posts on a page of my wordpress log and I just used:

query_posts($query_string . '&post_status=future,publish');

which worked flawlessly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文