Home Forums General Issues Post ID value is empty with get_field()


Post ID value is empty with get_field()

  • I’ve tried both get_field and the_field to populate an array that would then be sent out. My issue is that I cannot get the default current post id from get_field.

    My code works if I hard code a post id into it. (works like a charm). When I have my error reporting on when I echo the variable holding my id it shows the current id. So I’m a little stuck.

    $post_id = $post->ID;
    $comment = get_field('comments_linkedin',$post_id);
    $urllinkedin = get_field('submit_url_linkedin',$post_id);
    $image_url_linkedin = get_field('image_url_linkedin',$post_id);

    The array:

    Array ( [comment] => [title] => dear [submitted-url] => [submitted-image-url] => [description] => )

    When the id is echoed as mentioned above it shows up in the error report.

    I’m just wondering how get_field pulls the id and how I can have it work.

    i’ve tried:

    get_field(‘field_name’, $post->ID)
    get_field(‘field_name’, 34) //this one actually works and publishes everything successfully, obviously I need something that is more flexible.

Viewing 1 post (of 1 total)

The topic ‘Post ID value is empty with get_field()’ is closed to new replies.