Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a post-meta field for Neighborhood. I want to setup a url like: url.com/neighborhood/NEIGHBORHOOD-NAME

I know this would typically be handled by a CPT or custom taxonomy but it has to be done with a post-meta field in this case.

I also want this to use a custom template, not one of the standard templates.

I can easily link to the url but it returns a 404 page because nothing is associated with it.

Wordpress doesn't know what content to grab. Any ideas?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

There's the core function add_*/get_query_arg() that you can use to append stuff to the query and retrieve it.

So simply add a link somewhere, that points to your custom post types single.php template

single-{$custom_post_type}.php

Then append the query arg which would be ?wpse_meta_key=wpse_some_val and then do a switch on top of your template:

if ( 'wpse_some_val' === get_query_arg( 'wpse_meta_key' ) )
{
    get_template_part( 'special_query_template' );
}
else
{
    // do default stuff
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.