Support

Account

Home Forums General Issues get_field('image', $post_ID) is empty on pre_get_posts action in search.php

Helping

get_field('image', $post_ID) is empty on pre_get_posts action in search.php

  • I’m using the function get_field(‘image’, 7) to get the image for the post whose ID = 7.

    $image = get_field(‘image’, 7)

    When I var_dump $image there is info.

    However on the search page, $image is not being set – it’s empty – not even an array.

    I narrowed it down to an issue with action “pre_get_posts”. I’ve pasted the code here – http://pastebin.com/fZzvsTjt. If I remove that from functions.php $image is no longer empty and it’s an array.

    What can I change so $image is not empty (even though I pass a post id as a parameter)?

  • Hi @floatbit

    On you code, there is no usage of the get_feild function.

    It is possible that you method is resetting the global post and thus the get_field is failing.

    You could try loading the field into a variable before the function and then you can use it after the function.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘get_field('image', $post_ID) is empty on pre_get_posts action in search.php’ is closed to new replies.