jasmeet Posted March 6, 2014 Share Posted March 6, 2014 hello, on click this link, i am redirecting to page-listing-category.php page. and all listing are shown there. http://domain-name/listing-category/?a=hello but i want this link as http://domain-name/listing-category/hello ... i use this code in function.php add_rewrite_tag("%a%",'([0-9]+)'); $a = get_query_var("a"); // Wordpress way add_rewrite_rule('listing-category/([0-9]+)/?$', 'index.php?page_id=page-listing-category&a=$matches[1]', 'top'); add_rewrite_tag("%a%",'([0-9]+)'); add_rewrite_rule('listing-category/([0-9]+)/?$', 'index.php?page_id=page-listing-category&a=$matches[1]', 'top'); $wp_rewrite->flush_rules(); but, problem is the above isn't working ... can anypne suggest me something on this. ?? thanks. Link to comment https://forums.phpfreaks.com/topic/286755-custom-url-rewriting-in-wordpress/ Share on other sites More sharing options...
jairathnem Posted March 6, 2014 Share Posted March 6, 2014 have you tried permalinks? http://codex.wordpress.org/Using_Permalinks Link to comment https://forums.phpfreaks.com/topic/286755-custom-url-rewriting-in-wordpress/#findComment-1471631 Share on other sites More sharing options...
jasmeet Posted March 6, 2014 Author Share Posted March 6, 2014 yes... but for this link, i need to create my own custom url rewriting.. Link to comment https://forums.phpfreaks.com/topic/286755-custom-url-rewriting-in-wordpress/#findComment-1471634 Share on other sites More sharing options...
zantins Posted March 14, 2014 Share Posted March 14, 2014 add_rewrite_rule('listing-category/([0-9]+)/?$', 'index.php?page_id=page-listing-category&a=$matches[1]', 'top'); Lets use the above quoted line as an example. First thing i would suggest here is to remove the last slash, the question mark and the $ from your query string. You can put it back later after you tested a few things. Next you should reference the page slug with "pagename" not "page_id" The next thing would be that this function should be called within the wordpress "init" action hook. For example: add_action("init","my_init_function"); You need to hook into the "query_vars" hook and add your variables, for example your "a" query var to the wordpress query variables: function my_query_vars($vars){ $vars[] = "a"; return $vars; } add_filter("query_vars","my_query_vars"); Finally, go into the wordpress admin to Settings->permalinks and hit save, to refresh your permalinks setup. Give that a try, it may need some playing around with but that is the basics of what needs to be done. You would then access your query var in the page template as: get_query_var("a"); Link to comment https://forums.phpfreaks.com/topic/286755-custom-url-rewriting-in-wordpress/#findComment-1472640 Share on other sites More sharing options...
jasmeet Posted March 21, 2014 Author Share Posted March 21, 2014 Lets use the above quoted line as an example. First thing i would suggest here is to remove the last slash, the question mark and the $ from your query string. You can put it back later after you tested a few things. Next you should reference the page slug with "pagename" not "page_id" The next thing would be that this function should be called within the wordpress "init" action hook. For example: add_action("init","my_init_function"); You need to hook into the "query_vars" hook and add your variables, for example your "a" query var to the wordpress query variables: Finally, go into the wordpress admin to Settings->permalinks and hit save, to refresh your permalinks setup. Give that a try, it may need some playing around with but that is the basics of what needs to be done. You would then access your query var in the page template as: get_query_var("a"); thanks for your reply . Link to comment https://forums.phpfreaks.com/topic/286755-custom-url-rewriting-in-wordpress/#findComment-1473415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.