Showing posts with label custom arguments. Show all posts
Showing posts with label custom arguments. Show all posts

Friday, 1 March 2013

Custom arguments to add_filter

We can pass custom arguments to filters when using add_filter.

For example plugin needs to pass the order dynamically it can be done by using global variables.Sample code to change the order by using posts_orderby_request filter
.

global $corder;
$corder = 'asc';
add_filter( 'posts_orderby_request',function(){ 
                  global $corder; 
                  $val = " wp_posts.post_title $corder";
                  return $val;
                }
          );