tags:

views:

62

answers:

3

I would like to know if there's exists some simple code to get to the page i know its ID , I would like to create small input (no matter where in templates)from where the people can easily get to the page if they know it's page ID (4numeric ID is better to remember - permalink name you can mistake . I have the girls portfolio in wordpress - portfolio=pages x jobs in clubs offers=posts , I would like the girls portfolios to be easily findable by ID(s) , if possible the same for the posts=jobs in clubs The best solution little 4-5numeric input and send=go button in sidebar.php - index.php etc

A: 

I don't know if this is what you are asking, but you can get permalink using id i.e. if you have a pages' id the you can generate permalink like so, <?php echo get_permalink($page_or_post_id); ?> . So whenever you get $id of a page or post you can redirect or show link to that page/post

Pragati Sureka
Thanks a lot for your comment but i need the option from the answer above , when anybody can insert the page ID in a little 4numeric input box so the people after submit can be redirected to the page(girl portfolio page) easily (better to remember 4 number than the exact name(permalink) of the girl.)
Daniel
+1  A: 
justjoe
This is exactly what I was thinking !!! , thanks a lot for this code, but unfortunately it doesn't work in Wordpress 2.9.2 -:( , Where do I need to insert this code ? directly to the templates or some part to functions.php ? Theres no explanation where to insert it. But I'm happy at least with your code I can explain better this problem. Other thing this code works only with posts , not with pages
Daniel
I have also tried to put it in header.php between head and it showes me the error.
Daniel
you should put it in functions.php
justjoe
after try to using it, i know it's able to seek for post and pages. btw, what kind of error ? if i know i will answer but if it too hard maybe you should consult with the author
justjoe
thanks for your respond justjoe , i didn't notice your answers , i'm new here so I didn't see that somebody is responding and notify functions works here with big delay,btw. code is working now , author helped me , I posted the code down on this page. Thanks again for your help
Daniel
+1  A: 

Resolved !!! works perfect thanks to the author of this code who helped me to make it run from the website link above , so Thanks a lot to both men !!!Thanks to real author of the code and the editor who answered the first question .[link text][1]

<?php
}

function baka_show_form_redirect() {
      $form_search ='<form action="" method="post" name="redirect_to_post_id">
      <h4>Theme Feature</h4>
      <ol>
          <li><label for="post_id" title="Put numerical value of existing post ID">Redirect to ID (numerical) : </label>
          <input name="post_id" type="text" maxlength="4" class="description"
              style="width:30px;display:inline;border:none;color:#000" /></li>
      </ol>
        <input name="_redirect_to" type="hidden" value="' . get_permalink() . '" />
      </form>';

      echo $form_search;
}

function baka_validasi_post_id() {
    if( $_POST[ 'post_id' ] && $_POST[ 'post_id' ] != '' ) {
          $post_id = $_POST[ 'post_id' ];
          if (absint($post_id)) { //must be integer and not negative

              $url = get_permalink($post_id);

              if ($url) {
                  wp_redirect($url); echo "&nbsp;";
              } else {
                  $_redirect_to = $_POST[ '_redirect_to' ];
                  wp_die("ID can not be found … <a href ='" . $_redirect_to . "'>Back</a>");
              }
        }
  }
}

add_action('wp_head', 'baka_show_form_redirect');
add_action('init', 'baka_validasi_post_id'); 
?>

[1]: http://www.bakawan.com/log/howto-wordpress-redirect-based-on-post-id/comment-page-1/#comment-6654"Code author's site"

Daniel