GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   How can I grab th post ID from my wp blog, without changing the htaccess? (https://gfy.com/showthread.php?t=937624)

Si 11-09-2009 08:08 AM

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 :helpme

Thank you :thumbsup

JamesK 11-09-2009 08:20 AM

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.

darksoul 11-09-2009 08:20 AM

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

HowlingWulf 11-09-2009 08:28 AM

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

fris 11-09-2009 08:28 AM

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

:)

Si 11-09-2009 08:29 AM

Thanks guys, thats me sorted :thumbsup

Simple yet easy to miss. :)

Si 11-09-2009 08:39 AM

Quote:

Originally Posted by fris (Post 16530348)
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 :upsidedow


All times are GMT -7. The time now is 07:56 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123