您应该使用posts_join
和posts_where
用于修改JOIN和WHERE子句的筛选器。
add_filter( \'posts_join\' , \'se333659_posts_join\', 20, 2 );
add_filter( \'posts_where\' , \'se333659_posts_where\', 20, 2 );
function se333659_posts_join( $join, $query )
{
global $wpdb;
if ( isset($query->query_vars[\'_rev_of_publ\']) &&
$query->query_vars[\'_rev_of_publ\'] == \'1\' )
{
$join .= " LEFT JOIN {$wpdb->posts} AS rev_p ON ({$wpdb->posts}.post_parent = rev_p.ID) ";
}
return $join;
}
function se333659_posts_where( $where, $query )
{
global $wpdb;
if ( isset($query->query_vars[\'_rev_of_publ\']) &&
$query->query_vars[\'_rev_of_publ\'] == \'1\' )
{
$where .= \' AND rev_p.post_status = \\\'publish\\\' AND \'.$wpdb->posts.\'.post_date <> rev_p.post_date \';
}
return $where;
}
如何使用:在通过
_rev_of_publ
参数(名称可以更改)为
WP_Query
.
$args = [
\'post_type\' => \'revision\',
\'post_status\' => \'any\', // default value is \'publish\'
\'_rev_of_publ\' => 1,
];
$my_query = new WP_Query( $args );
Here 您将找到有关使用
WP_Query
.