A simple solution would be using the rewrite
and 'with_front
arguments while registering the post type. Try this..
'with_front' => false,
'rewrite' => array( 'slug' => '%services%/%areas%'),
Then add a filter to post_type_link
to replace the tags with terms.
function wpse277778_rewrite_urls( $url, $post ) {
if ( 'listings' == get_post_type( $post ) ) {
$services = wp_get_post_terms( $post->ID, 'services' );
$areas = wp_get_post_terms( $post->ID, 'areas' );
$url = str_replace( '%services%', $services[0]->slug, $url );
$url = str_replace( '%areas%', $areas[0]->slug, $url );
}
return $url;
}
add_filter( 'post_type_link', 'wpse277778_rewrite_urls', 10, 2 );
Please note, this is a barebone code and you need to do some checking with conditional tags to output error free $url
. Also, you should set a default services and area in case no terms are associated.