gpt4 book ai didi

php - 类别/术语的 WordPress SQL 查询

转载 作者:行者123 更新时间:2023-11-29 03:14:34 25 4
gpt4 key购买 nike

<分区>

我正在稍微修改一个插件以满足我的需要,并且需要更改此查询以仅返回一个类别的帖子 ID。我知道它与 INNER JOIN 有关,但无法正确查询。

这是原始查询

$query = "SELECT ID as PID FROM $wpdb->posts";
$results = $wpdb->get_results($querydetails,ARRAY_A);

编辑:好的,我找到了查询的方法

$query = "
SELECT ID as PID FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships ON
($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON
($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
WHERE $wpdb->posts.post_status = 'publish'
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->term_taxonomy.term_id = 3
";

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com