gpt4 book ai didi

mysql - Wordpress SQL 语句排除某个类别

转载 作者:行者123 更新时间:2023-11-29 02:06:56 26 4
gpt4 key购买 nike

我想知道如何修改此语句以排除某个类别,即。类别 id = 14

请注意,wordpress 类别位于不同的表格中。

引用为 term_relationships,类别为 term_taxonomy_id

<?php 
$now = gmdate("Y-m-d H:i:s", strtotime('0 days'));

$request = $wpdb->prepare("SELECT ID, post_title, post_date, post_excerpt,LEFT(post_content,$sqllimit) AS short_post_content FROM $wpdb->posts WHERE post_status = 'publish' ");
if($hide_pass_post) $request .= "AND post_password ='' ";
if($include_pages) $request .= "AND (post_type='post' OR post_type='
else $request .= "AND post_type='post' ";

$request .= "AND post_date_gmt > '$now' ORDER BY post_date ASC LIMIT $skip_posts, $returnnum";
$posts = $wpdb->get_results($request); ?>

最佳答案

$request = $wpdb->prepare("SELECT * 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->term_taxonomy.term_id = 3
AND $wpdb->term_taxonomy.term_id <> 14
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->posts.post_type = 'post'
AND $wpdb->posts.post_status = 'publish')");

关于mysql - Wordpress SQL 语句排除某个类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4302520/

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