2

we have a somewhat unique problem with a specific Custom Post Type that was developed for a client. It basically boils down to a need to disable the single post view for any posts that have been assigned to a specific taxonomy in the CPT we created.

EXAMPLE:

Custom Post Type: 'rentals'

Taxonomies: 'apartment', 'condo', 'rented'

Permalink Structure (regardless of taxonomy): http://www.domain.com/rentals/post-title/

The unique taxonomy is 'rented', which is shown as just a landing page (taxonomy listing) of all rentals that are no longer available, on a separate page from all the main rentals. There is no click-through to the single post from this landing page, so you can't get to the single post directly. It's just the thumbnail, title and address from each rental listing, laid out in a grid. The other taxonomies are grouped together in a main 'rentals' page, and they do have click-through's to single posts.

BUT, even though you can't get to the single post for these 'rented' listings directly, they are still indexed by search engines, and technically 'viewable' with knowledge of the right permalink.

And the bigger problem is that listings that begin as assigned to the other taxonomies (e.g., 'apartment' or 'condo'), are then changed to the 'rented' taxonomy once no longer available. These definitely are (and should be) indexed, and more-so, direct links have been sent to clients in email marketing campaigns. So if a client clicks an old email for a listing that should not be viewable apart from the 'Rented' landing page, they can still get to the single post page for that listing.

The client 'could' just change the permalink when they convert current listings to 'rented', but they also tend to have a lot of listings with the same title. So WordPress by default adds an increment to the permalink for each new post (e.g., 'colonial-park-04'), and if they changed the original posts' permalink, Wordpress would use a pre-existing permalink again, and the 'old' link would be available again but with a new property (even worse). And this doesn't solve the issue of posts that are originally created as 'rented' being indexed.

  • How best could/should this be remedied???

THANKS!!!

3

I use template_redirect hook for this purpose. I suppose rented in your question is not taxonomy itself, but one term of some taxonomy.

function my_page_template_redirect() {
    if( is_singular( 'rentals' ) && has_term('rented', 'your taxonomy name') ) {
        wp_redirect( home_url(), 301 );
        exit();
    }
}
add_action( 'template_redirect', 'my_page_template_redirect' );

Before page rendering, WP checks if CPT rentals single post is viewed, and if it has rented term ... and if so, it will redirect visitor somewhere else.

  • Another idea would be to change the post status of the affected posts :-) – Pieter Goosen Aug 19 '15 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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