Mathieu
Mathieu

Reputation: 761

Wordpress - Query post from favorited author

I use a third party plugin called "Favorite Author". I want to filter posts with the author I favorited. I tried this :

$fav_author_list = get_user_option( 'favorite-authors', fav_authors_get_user_id() );
print_r($fav_author_list);
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; 
query_posts( array( 'author__in'=> array_keys($fav_author_list) , 'paged' => $paged, ) ); 

That prints something like :

Array (
    [1] => 3
    [2] => 1
)

Where 3 and 1 are the user ID I follow. But the displayed posts don't match with the author I favorited. What's wrong ?

Upvotes: 1

Views: 50

Answers (1)

miken32
miken32

Reputation: 42715

array_keys will return the keys from the array, not the values. Just pass the $fav_author_list array directly and it should work.

$fav_author_list = get_user_option( 'favorite-authors', fav_authors_get_user_id() );
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; 
query_posts( array( 'author__in'=> $fav_author_list, 'paged' => $paged, ) ); 

Upvotes: 1

Related Questions