SOLVED Custom Add rewrite rule and Get string

I have a problem, I try to create clean urls for seo. but I do not get any parameters using GET, which is wrong in my code

add_action( ‘init’, ‘listing_search_url’ );
function listing_search_url()
add_rewrite_tag(‘%type%’, ‘([^&]+)’);
add_rewrite_tag(‘%search_location%’, ‘([^&]+)’);

this work but have errors so i just make a change and work perfectly

function wpd_foo_get_param() {
if( false !== get_query_var( ‘search_location’ ) ){
$_GET[‘search_location’] = get_query_var( ‘search_location’ );
add_action( ‘parse_query’, ‘wpd_foo_get_param’ );

This code work

add_action( ‘parse_query’, ‘listing_get_query_vars’ );
function listing_get_query_vars() {
//if you use – _ + on your url the form just recive a space
if(!empty( get_query_var( ‘search_location’ )) ){
$_GET[‘search_location’] = str_replace(array(‘-‘,’_’,’+’),’ ‘,get_query_var( ‘search_location’ ));

Read more here:: SOLVED Custom Add rewrite rule and Get string

Leave a Reply

Your email address will not be published. Required fields are marked *