I played with the idea of the filter and tried to pass a variable into the function filter_where($var) but apparently add_filter(‘post_where’,’filter_where(‘.$var.’)’); does not take this too well. The script would run in the loop while but would halt after getting an error call on hook name.
To fix that, I had to make the variable global inside the function. It works but appears to be a clumsy solution.
<?php
function filter_where() {
global $this_post;
global $this_author;
$w = " AND ID <=".$this_post." AND post_author=".$this_author;
return $w;
}
//sample first loop
if (have_posts()) : while (have_posts()) : the_post();
$what_post=$post->ID; $who_author=$author_id;
//assume an elaborate sorting condition statement
if($found_author==$who_author || $found_post==$what_post){
$this_author=$found_author;
$this_post=$found_post;
}
//sample second loop
$myPosts = new WP_Query(); add_filter('posts_where', 'filter_where');
$myPosts->query('posts_per_page=10');
while ($myPosts->have_posts()): $myPosts->the_post();
the_content(__("(...)"));
endwhile;
//closing the first loop
endwhile;
endif;
?>
Would appreciate any thoughts on this. Thanks!