WordPress.org

Ready to get started?Download WordPress

Forums

Get post id with attachment url (4 posts)

  1. Anonymous
    Unregistered
    Posted 5 years ago #

    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!

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    $postid = get_the_ID();

  3. Anonymous
    Unregistered
    Posted 5 years ago #

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

  4. Anonymous
    Unregistered
    Posted 5 years ago #

    I found the solution

    $post->post_parent;

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags