I have the following code in WordPress so as to try and achive a stage where I can use esc_url(get_permalink() . '?month=' . get_query_var('month'));
.
In an attempt to learn more about WordPress and to make a class that would allow me to add more values as and when I need them, I created the following class and linked it into the query_vars filter:
//Create the needed GET 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 an array of values //
foreach($this->_custom_vars as $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 does not work, instead, when the class is active and when I create a new instance all pages on my website will stop working and I will simple be directed to my root address. However, the function "seems" to be working as the print_r()
will indeed print the values of Array ( [0] => month [1] => day )
so the method must be getting passed to the query_var hook in some shape or form.
The second part of the code that is commented out is me trying the standard function that simply returns static values. This works and using the normal esc_url(get_permalink() . '?month=' . get_query_var('month'));
works as expected. Any ideas? (one last thing, is there a way of making this http://www.sitename/pagename/month
).
Thank you for any and all help,