Dynamic redirect

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?

Topic pods-framework custom-content redirect Wordpress

Category Web


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());
});

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.