我现在已经建立了一个解决方案,但我真的很想知道是什么导致了这种情况。解决方法是将“suppress\\u filters”更改为true,然后添加一个函数,将其添加到SQL的where子句中。。。
But I would rather know how to fix this at the root rather than a bandaid
我的变通方法是通过在我的函数中添加以下内容来完成的。php:
function leads_post_type_where( $where ) {
$clause = "";
$post_types=get_post_types($args,\'names\');
foreach ($post_types as $post_type ) {
if (trim($post_type)!="" && trim($post_type) != "ditl_post") {
if ($clause==""){
$clause .= "\'$post_type\'";
} else {
$clause .= ", \'$post_type\'";
}
}
}
$where .= \' AND post_type NOT IN (\'.$clause.\')\';
return $where;
}
然后将my get\\u posts调用更新为:
$args = array(
\'numberposts\' => 5,
\'order\' => \'DESC\',
\'orderby\' => \'date\',
\'post_type\' => \'leads\',
\'post_status\' => \'publish\',
\'post__not_in\' => array($post->ID),
\'suppress_filters\' => false
);
add_filter( \'posts_where\', \'leads_post_type_where\' );
$result = get_posts($args);
remove_filter( \'posts_where\', \'leads_post_type_where\' );