Nasıl birden fazla yazarın gelen mesajlar Wordpress sorgulayabilir mi?
something like:
query_posts('author=9,10&post_status=publish&orderby=date')
Bu olsa çalışma değildir.
Bu belgelere göre hiçbir resmi destek: http://codex.wordpress.org/Function_Reference/query_posts - başlığı "Yazar Parametreleri" altında.
Ancak, kaynak koduna kazma aksi ortaya koymaktadır: http://wordpress.taragana.net/nav.html?wp-includes/classes.php.html#query_posts.
$author_array = preg_split('/[,\s]+/', $q['author']);
for ($i = 1; $i < (count($author_array)); $i = $i + 1) {
$whichauthor .= ' '.$andor.' post_author '.$eq.' '.intval($author_array[$i]);
}
$whichauthor .= ')';
Lütfen virgülle ayrılmış listesi I go ahead ve WP_Query::get_posts() işlevi ayıklama hatları atarak başlamak istiyorum doğru şekilde kullanıldığını görmek için. Örneğin, nihai değeri nedir $whichauthor?
Ben bunu yapmak için doğru yol olduğunu düşünüyorum:
function yclads_posts_where_followed_authors($where) {
global $wpdb;
$authors_ids = array(0,1,2,3);//array of authors IDs
if (count($authors_ids) > 0)
{
$where .= ' AND ' . $wpdb->posts . '.post_author IN(' . implode (',',$authors_ids) . ') ';
}
else
{
$where .= ' AND 1=2'; //do not return results
}
return $where;
}
add_filter('posts_where', 'posts_where_filter_authors');
Query_posts () işlevi yalnızca bir seferde bir yazar sorgulama desteklemek gerekiyordu. Eğer birden fazla yazar görüntülemek istiyorsanız, ben aşağıdakilerden birini denemenizi öneririz:
Bu biraz farklı bir döngü farklı sorgu parametreleri ile bir sayfa veya yazı üzerine mutliple kez çalışacaktır:
<?php $my_query = new WP_Query('author=9&post_status=publish&orderby=date'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
<?php endwhile; ?>