php - Wordpress - Passing a class method to the query_var hook -
i have following code in wordpress try , achive stage can use esc_url(get_permalink() . '?month=' . get_query_var('month'));
.
in attempt learn more wordpress , make class allow me add more values , when need them, created following class , linked query_vars filter:
//create needed vars // $custom_query_values = array('month','day'); new _custom_query_vars($custom_query_values); class _custom_query_vars { public $_custom_vars; function __construct($custom_vars){ $this->_custom_vars = $custom_vars; add_filter('query_vars',array(&$this, '_add_custom_querys')); } public function _add_custom_querys(){ // return array of values // foreach($this->_custom_vars $value) { $vars[] = $value; } print_r($vars); return $vars; } } /*function add_custom_query_var( $vars ){ $vars[] = "month"; $vars[] = "day"; return $vars; } add_filter( 'query_vars', 'add_custom_query_var' ); */
the above code not work, instead, when class active , when create new instance pages on website stop working , simple directed root address. however, function "seems" working print_r()
indeed print values of array ( [0] => month [1] => day )
method must getting passed query_var hook in shape or form.
the second part of code commented out me trying standard function returns static values. works , using normal esc_url(get_permalink() . '?month=' . get_query_var('month'));
works expected. ideas? (one last thing, there way of making http://www.sitename/pagename/month
).
thank , help,
i not sure try this.
public function _add_custom_querys(){ $vars = array(); foreach($this->_custom_vars $value){ array_push($vars,$value); } return $vars; }
Comments
Post a Comment