Ok. There are few things wrong here.
query_posts
isn’t mean to be used that way so don’t. Try the same code with $likes=new WP_Query(array(...
instead.
$likes=new WP_Query(array(
'post_type' => 'post',
'ignore_sticky_posts' => true,
'filter_type' => 'user_liked',
'filter_user' => $user_id
));
That is problem one. Then even if $likes
were set correctly you’d clobber it.
$likes= array();
Why would you expect to have data in $likes
after you’ve erased all of the data? Don’t do that. Remove that line.
Now this:
while (have_posts()) :
$likes[]=the_post() ;
endwhile;
…is pointless. After you run the query $likes
is already a collection of posts. Run var_dump($likes)
and you will see what I mean. There is no need to loop over it just to do what is already been done. Just return $likes
or loop over it and do something, like echo content.
Besides, using the_post
like that wouldn’t work. That isn’t what the the_posts
method does.
If, on the other hand, you are trying to extract, for example, the post content you’d want…
while ($likes->have_posts()) :
$likes->the_post();
$cont[] = $post->post_content;
endwhile;
I’d really suggest you take some time to read about creating loops.
You can do about the same with get_posts
but the loops are a little different.
Also, why are you mixing PHP’s mysql_*
functions with $wpdb
? And why are you using global $wpdb
only to then clobber it? Why don’t you just use a different name for your database instance?
Hopefully that helps.