WordPress.org

Support

Support » Plugins and Hacks » Get post id with attachment url

Get post id with attachment url

  • Hi all,

    if a have this url:
    domain.com/?attachment_id=198

    ¿can I get the post id of this attachment in atattchment.php or image.php?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • $postid = get_the_ID();

    Thanks otto42,

    I put that code and i got attachment ID not post ID, let me explain:

    I wrote a post and i uploaded 10 pictures

    The post ID:
    ?p=10

    and attachment id:
    ?attachment_id=1,
    ?attachment_id=2,
    ?attachment_id=3,….?attachment_id=10,

    If i put in browser domain.com?attachment_id=4,¿ how can i get post_id ?(in this case p=10)

    pd: my english sucks, sorry 🙁

    I found the solution

    $post->post_parent;

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get post id with attachment url’ is closed to new replies.
Skip to toolbar