I have 2 taxonomies type and city
I want to have page where it will dynamically query a city and type depending on the link for example:
type/condo/city/toronto should get all my properties from Toronto that is a condo.
I tried adding a taxonomy page where it would have a filename of taxonomy-type-city.php but it seems to not work.
Also tried to add a custom rewrite rule and query but still does not work. Is this possible?
<?php
// code will goes here
function custom_rewrite_rule() {
add_rewrite_rule('^property-type/([^/]*)/city/([^/]*)/?','?property_type=$matches[1]&city=$matches[2]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);
function custom_query( $query ) {
if ( !is_admin() && $query->is_main_query() ) {
if ( $query->is_tax( 'property_type' ) || $query->is_tax( 'city' ) ) {
$query->set( 'tax_query', array(
'relation' => 'AND',
array(
'taxonomy' => 'property_type',
'field' => 'slug',
'terms' => get_query_var( 'property_type' ),
),
array(
'taxonomy' => 'city',
'field' => 'slug',
'terms' => get_query_var( 'city' ),
),
) );
}
}
}
add_action( 'pre_get_posts', 'custom_query' );
?>
index.php
to the second parameter to get it working:index.php?property_type...
.index.php
not sure why it's still not workingindex.php
.