Try this:
$gallery_id = get_field('gallery', $post->ID );
the_field()
(docs) is for directly outputting a value, while get_field()
(docs) is for getting the value and for example setting a variable with it.
Edit: I misread your question and saw you already tried this. In that case, try var_dump($gallery_id)
, look for the returned values, and use the correct array key in returning the gallery ID.
So if the array key is key
, you'd use $gallery_id['key']
to output this key.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…