admin管理员组文章数量:1429368
I would be the first to admit that I know next to nothing about SQL queries, but after numerous searches and some trial and error I was able to cobble together a query that returned the results I was looking for.
The problem now is I need to return the results from two taxonomies and I am not sure how to do it. This is my query that returns the results from the first taxonomy:
$wpdb->get_results(
"SELECT {$wpdb->prefix}posts.ID, {$wpdb->prefix}posts.post_title, {$wpdb->prefix}posts.post_author, {$wpdb->prefix}posts.post_date, {$wpdb->prefix}terms.name AS 'layout_type'
FROM
{$wpdb->prefix}posts
INNER JOIN {$wpdb->prefix}term_relationships ON ( {$wpdb->prefix}posts.ID = {$wpdb->prefix}term_relationships.object_id )
INNER JOIN {$wpdb->prefix}terms ON ( {$wpdb->prefix}term_relationships.term_taxonomy_id = {$wpdb->prefix}terms.term_id )
INNER JOIN {$wpdb->prefix}term_taxonomy ON ( {$wpdb->prefix}term_relationships.term_taxonomy_id = {$wpdb->prefix}term_taxonomy.term_taxonomy_id )
WHERE
{$wpdb->prefix}posts.post_type = 'et_pb_layout'
AND {$wpdb->prefix}term_taxonomy.taxonomy = 'layout_type'
ORDER BY {$wpdb->prefix}posts.ID DESC",
ARRAY_A
);
And here is the query that returns the second one:
$wpdb->get_results(
"SELECT {$wpdb->prefix}posts.ID, {$wpdb->prefix}posts.post_title, {$wpdb->prefix}posts.post_author, {$wpdb->prefix}posts.post_date, {$wpdb->prefix}terms.name AS 'scope'
FROM
{$wpdb->prefix}posts
INNER JOIN {$wpdb->prefix}term_relationships ON ( {$wpdb->prefix}posts.ID = {$wpdb->prefix}term_relationships.object_id )
INNER JOIN {$wpdb->prefix}terms ON ( {$wpdb->prefix}term_relationships.term_taxonomy_id = {$wpdb->prefix}terms.term_id )
INNER JOIN {$wpdb->prefix}term_taxonomy ON ( {$wpdb->prefix}term_relationships.term_taxonomy_id = {$wpdb->prefix}term_taxonomy.term_taxonomy_id )
WHERE
{$wpdb->prefix}posts.post_type = 'et_pb_layout'
AND {$wpdb->prefix}term_taxonomy.taxonomy = 'scope'
ORDER BY {$wpdb->prefix}posts.ID DESC",
ARRAY_A
);
How can I combine these two queries into one?
I cannot use normal WordPress commands to return these results because at the time I need them the taxonomies are not yet loaded.
本文标签: custom taxonomyReturn terms from multiple taxonomies using wpdb
版权声明:本文标题:custom taxonomy - Return terms from multiple taxonomies using $wpdb 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745425043a2658072.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论