Pass variable to filter?
-
Writing a function to do a wp_query with a ‘where’ clause:
function nc_custom_query($my_where_clause){ function nc_dynamic_where( $where = '' ) { $where .= $my_where_clause; return $where; } add_filter( 'posts_where', 'nc_dynamic_where' ); $dynamic = new WP_Query( array( 'post_type' => 'my_type', 'orderby' => 'rand', 'posts_per_page' => $number )); remove_filter( 'posts_where', 'nc_dynamic_where' ); return $dynamic; }
Only this does not work…. since the filter funtion
nc_dynamic_where
can only accept$where
and ouput$where
…So, how do I get the variable
$my_where_clause
into the filter?Caveat: I’m trying to avoid
global
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Pass variable to filter?’ is closed to new replies.