Using Custom Fields in Custom Post Type URL

I managed to fix this.

Basically I changed the permastruct to this:

$wp_rewrite->add_permastruct('showroom', 'location/%state%/%city%/%showroom%', false);

I then grabbed state & city as two separate variables, replacing it in the permalink structure using these lines:

$permalink = str_replace('%state%', $state, $permalink);
$permalink = str_replace('%city%', $city, $permalink);

With $state & $city grabbed using get_post_meta from the post.

Leave a Comment