Using PODS, I created a content type "sorteio" (lottery).

I made a routine in functions.php to create the title automatically and, after creating the first record, url looks like this: http://sortemaniasudoeste.com.br/sorteio/sorteio-001-06-05-2018/.

But it does not matter, this url should be disregarded because the records of this content type "sorteio" will be shown through a special script that I created: http://sortemaniasudoeste.com.br/edicao/?id=632, where "632" was the id created for this record.

I installed the Yoast SEO plugin and unfortunately I forgot to remove this content type from the XML Sitemaps list, so Google is indexing the original URL, which should not be shown.

I initially thought of creating a redirect inside the functions.php of my theme (Astra), but nothing is working, because apparently the page ID does not appear correctly in functions.php.

My question is: what should I do in this case? Is it better to redirect the page? How do I redirect it into the functions.php? Is there a better way?

1 Answer 1


Already solved using this code inside functions.php:

add_action('template_redirect', function() {
    if (is_single() && get_post_type(get_queried_object_id()) == 'sorteio')
            wp_redirect('edicao/?id=' . get_queried_object_id());
  • Upvoted for answering your own question :)
    – Tom J Nowell
    Commented May 9, 2018 at 21:02
  • Thank you! Still remains the question if is it the better way? Commented May 9, 2018 at 21:15
  • This looks optimal, I doubt you'll find a better way
    – Tom J Nowell
    Commented May 9, 2018 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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