You can use the add_filter
line inside the template itself & no filter in the “functions.php” file. Then just after retrieving the posts remove that filter with a call to remove_filter
. The actual function may still reside in the functions.php file
add_filter('posts_orderby', 'edit_posts_orderby');
// get all the posts for this specific loop here
remove_filter('posts_orderby', 'edit_posts_orderby');
This ensures that no other loop gets affected from this filter
In case you want to use another way, you can change the filter to accept 2 parameters, the 2nd parameter here is the concerned WP_Query object. In that object, you can examine the query parameters to determine weather to apply the filter or not
add_filter('posts_orderby', 'edit_posts_orderby', 10, 2);
function edit_posts_orderby($orderby_statement, $query) {
if($query->get('cat') != 6)
return $orderby_statement;
// apply the random seed here
}