How to pass extra variables in URL with WordPress
There are quite few solutions to tackle this issue. First you can go for a plugin if you want:
- WordPress Quickie: Custom Query String Plugin
Or code manually, check out this post:
- Passing Query String Parameters in WordPress URL
Also check out:
add_query_arg
pass variable through url in wordpress
Well, as suggested by @vl4d1m1r4 , I have used the web server(in my case apache) rewrite rule to rewrite the path. Some-what I have achieved the desired result.
In function.php
I have written the following code to update the rewrite rule in wordpress(.htaccess)
add_filter( 'query_vars', 'add_custom_query_vars' );
function add_custom_query_vars( $vars )
{
array_push($vars, "test_year", "test_postid", "test_title");
return $vars;
}
function custom_rewrite_rule()
{
add_rewrite_rule('^test/([^/]*)/([^/]*)/([^/]*)?','index.php?pagename=test&test_year=$matches[1]&test_postid=$matches[2]&test_title=$matches[3]','top');
}
add_action('init', 'custom_rewrite_rule');
After adding the above code, I have re-saved the permalink settings(setting>>permalink)
To Get the parameter in custom-template-page i.e test.php. I have used the following query.
echo get_query_var('test_title');
echo get_query_var('test_postid');
echo get_query_var('test_year');
How to pass extra variable in WP admin edit.php
You can do this with admin_menu
action,
The following code should work :
add_action( 'admin_menu', function(){
global $menu, $submenu;
foreach( $submenu['edit.php'] as $k => $v ){
if( $v['2'] == 'edit.php' ) {
$submenu['edit.php'][$k]['2'] = 'edit.php?orderby=123&order=desc';
break;
}
}
}, 99 );
Related Topics
PHP to Search Within Txt File and Echo the Whole Line
PHP Class Instantiation. to Use or Not to Use the Parentheses
JavaScript Equivalent of PHP'S In_Array()
How to Insert HTML to PHP Domnode
MySQL Datetime Fields and Daylight Savings Time - How to Reference the "Extra" Hour
PHP Library For Parsing Xml With a Colons in Tag Names
Jquery Ui Sortable, Then Write Order into a Database
PHP Json_Encode Not Working on Arrays Partially
PHP Convert String to Hex and Hex to String
Trying to Get Property of Non-Object - Laravel 5
Posting Raw Image Data as Multipart/Form-Data in Curl
How to Pass Extra Variables in Url With Wordpress
Fatal Error: Class 'PHPmailer' Not Found