• 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)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    $postid = get_the_ID();

    Thread Starter 783957

    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 🙁

    Thread Starter 783957

    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.