Created
October 27, 2020 22:34
-
-
Save jetsloth/9b716e053877c0368dce5e8f8938f5e8 to your computer and use it in GitHub Desktop.
Filter Gravity Wiz Populate Anything to add Image Choices from post featured image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( "gppa_input_choices", "gppa_populate_featured_image_choices", 100, 3 ); | |
function gppa_populate_featured_image_choices( $choices, $field, $objects ) { | |
if ( ! property_exists($field, 'imageChoices_enableImages') || ! $field->imageChoices_enableImages ) { | |
return $choices; | |
} | |
$i = 0; | |
foreach( $choices as &$choice ) { | |
$post_object = $objects[$i]; | |
$post_id = $post_object->ID; | |
if ( !has_post_thumbnail($post_id) ) { | |
continue; | |
} | |
$choice['imageChoices_image'] = get_the_post_thumbnail_url( $post_id, "small" ); | |
$choice['imageChoices_imageID'] = get_post_thumbnail_id( $post_id ); | |
$i++; | |
} | |
return $choices; | |
} |
-- Please reply above this line --
Hello Jetsloth,
We received your email request! Someone from our team will get back to
you as soon as possible. We're Australian Sloths and work 9am-5pm, Mon
to Fri so we'll get back to you during our sloth business hours!
Be sure to check out our support documentation here
https://jetsloth.com/support/ [1] for any help or advice.
Thank you!
Links:
------
[1] https://jetsloth.com/support/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've successfully modified this to work with an ACF image field (in this case 'front_image') as well: