WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] The $post->ID is not correct on some pages (5 posts)

  1. gagnonconsulting
    Member
    Posted 4 years ago #

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

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Um.... category/archive pages don't have post ids.

  3. gagnonconsulting
    Member
    Posted 4 years ago #

    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?

  4. esmi
    Forum Moderator
    Posted 4 years ago #

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

    http://codex.wordpress.org/Conditional_Tags

  5. gagnonconsulting
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic