• Resolved gagnonconsulting

    (@gagnonconsulting)


    I have added the following code to the beginning of my header.php file so I can redirect the page if the ‘direct_jump’ metapost data value is set. That part works (with the print and header statements commented appropriatly), but I have found that often the $post->ID value is incorrect, and it will jump to the redirect page when it is not supposed to. It looks like the $post array is not getting cleared or set correctly when I go to some pages, including the home page and the main category page of the posts. Any ideas on how to proceed?
    — $thisPost = $post -> ID;
    — $gotoURL = ”;
    — $gotoURL = get_post_meta($thisPost, ‘direct_jump’, true);
    — if ($gotoURL != ”) {
    — print (“thisPost = $thisPost, “);
    — print (“header(‘Location: $gotoURL’);”);
    — //header(‘Location: ‘.$gotoURL);
    — }

Viewing 4 replies - 1 through 4 (of 4 total)
  • Um…. category/archive pages don’t have post ids.

    Thread Starter gagnonconsulting

    (@gagnonconsulting)

    OK, thanks. I guess I was given some bad info. Basically, I am trying to redirect to a specific URL if the ‘direct_jump’ metapost data value of a post is set (to a URL) when I click on a post link. Any idea how to do this?

    You could use conditionals first – is_category(), is_single etc. Then based on the results, test on post id or cat id etc.

    https://codex.www.ads-software.com/Conditional_Tags

    Thread Starter gagnonconsulting

    (@gagnonconsulting)

    Thank you, that does the trick. I am still getting confused as to which type of pages I am looking at (archive vs. category vs. post, etc.) but going through the codex functions reference is helping.

    Thanks for your help on this.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘The $post->ID is not correct on some pages’ is closed to new replies.