This snippet will alter the listing URL to include phone number of the listing:Â www.site.com/listings/3331542847/listing-name/
In your child theme functions.php file add this code.
function listing_post_type_link($permalink, $post) { // Abort if post is not a listing if ($post->post_type !== 'listing') return $permalink; // Abort early if the placeholder rewrite tag isn't in the generated URL if (false === strpos($permalink, '%')) return $permalink; $find = array( '%phone%' ); $phone = get_post_meta($post->ID,'_phone',true); $replace = array( $phone ); $replace = array_map('sanitize_title', $replace); $permalink = str_replace($find, $replace, $permalink); return $permalink; } add_filter('post_type_link', 'listing_post_type_link', 10, 2); function change_listing_slug($args) { $args['rewrite']['slug'] = 'listing/%phone%'; return $args; } add_filter('register_post_type_listing', 'change_listing_slug');
After that go to Settings -> Permalinks, and click Save to renew new permalinks