I have this file that has always gotten the wordpress post_id correctly:


WP Post ID: <?php echo get_the_ID(); ?>

-Text test-

But now I have created a rewrite rule for that file, and the redirect works, but it doesn't get the post_id, but it does show "-Text test-" that I added:

function custom_rewrite_basic() {
  add_rewrite_rule('^goto/([0-9]+)/?', 'wp-content/themes/default/template-parts/goto.php?p=$matches[1]', 'top');
add_action('init', 'custom_rewrite_basic');

function custom_rewrite_tag() {
  add_rewrite_tag('%goto%', '([^&]+)');
add_action('init', 'custom_rewrite_tag', 10, 0);

I appreciate any help you can give me.

Your Answer

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

Browse other questions tagged or ask your own question.