How can I grab th post ID from my wp blog, without changing the htaccess?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Si
    Such Fun!
    • Feb 2008
    • 13900

    #1

    How can I grab th post ID from my wp blog, without changing the htaccess?

    I need to grab my post ID number from some of my blog posts for this plugin I'm trying to configure and can't think how to do it without changing my htaccess backwards and forwards.

    for example,

    urloftheblog.com/post-name-is-here/

    I need the /?p=22 but without having to change the htaccess everytime

    It's fine at the moment because the blog is new and ain't got to worry about fucking anything up but I'd rather know a way to do it in the future.

    If that makes sense and I didn't confuse you, please

    Thank you
  • JamesK
    hi
    • Jun 2002
    • 16731

    #2
    You can look it up from the admin panel. Mouseover the post links and you'll see the ID's.

    Another option is to modify the template slightly and put the post ID in a HTML comment (for example <!-- ID -->) so you can view it from the source. You can see the ID tag and how to call it in your templates here:

    http://codex.wordpress.org/Template_Tags/get_posts

    You could even make it so only logged in admins could see it.
    Last edited by JamesK; 11-09-2009, 06:22 AM.
    M3Server - NATS Hosting

    Comment

    • darksoul
      Confirmed User
      • Apr 2002
      • 4997

      #3
      in /wp-admin/ go and edit the post
      it will look like:
      wp-admin/post.php?action=edit&post=435
      post=xxx its your id
      1337 5y54|)m1n: 157717888
      BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
      Cambooth

      Comment

      • HowlingWulf
        Confirmed User
        • Nov 2001
        • 1662

        #4
        If it's a wordpress plugin just use the wordpress functions to get the id in or out of the loop. A google search will show you how.

        If you need to use the url then try
        function get_post_by_title($page_title, $output = OBJECT) {
        global $wpdb;
        $post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='post'", $page_title ));
        if ( $post )
        return get_post($post, $output);

        return null;
        }
        WP Porn directory/review theme Maddos $35.

        webmaster AT howling-wulf.com

        Comment

        • fris
          Too lazy to set a custom title
          • Aug 2002
          • 55679

          #5
          comon, give us a challenge :p

          in the loop of course

          Code:
          <? echo $post->ID; ?>
          or you could add it to functions.php in your theme

          Code:
          function print_postid() {
               global $post;
               $postid = $post->ID;
               return $postid;
          }
          Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

          Comment

          • Si
            Such Fun!
            • Feb 2008
            • 13900

            #6
            Thanks guys, thats me sorted

            Simple yet easy to miss.

            Comment

            • Si
              Such Fun!
              • Feb 2008
              • 13900

              #7
              Originally posted by fris
              comon, give us a challenge :p
              LOL its one of them things thats right in front of you yet you forget, but nevermind

              Speaking of challenges, haven't had one of them with wordpress for a while so can't help you there

              Comment

              Working...