下面是一个示例—测试和工作。
SQL查询是:
AND ({$wpdb->posts}.post_content != \'\' OR {$wpdb->posts}.post_excerpt != \'\')
例如:
<?php
// This would be in functions.php or somewhere else where appropriate.
function posts_where_require_content_or_excerpt( $where, $wp_query ) {
global $wpdb;
$where .= " AND (" .
" {$wpdb->posts}.post_content != \'\'" .
" OR {$wpdb->posts}.post_excerpt != \'\'" .
")";
return $where;
}
// -- SAMPLE IMPLEMENTATION --
add_filter( \'posts_where\', \'posts_where_require_content_or_excerpt\', 10, 2 );
query_posts( array(
\'post_type\' => \'post\',
\'posts_per_page\' => 5,
\'ignore_sticky_posts\' => true,
) );
remove_filter( \'posts_where\', \'posts_where_require_content_or_excerpt\', 10, 2 );
if ( have_posts() ) {
echo \'<ul>\';
while ( have_posts() ) {
the_post();
echo \'<li>\';
echo \'<h2>\'; the_title(); echo \'</h2>\';
echo \'<p>\'; the_excerpt(); echo \'</p>\';
printf( \'<p><a href="%s">Read More →</a></p>\',
esc_url( get_permalink() ) );
echo \'</li>\';
}
echo \'</ul>\';
//the_posts_pagination(); // Needs extra work.
}
wp_reset_query();