Skip to content

Instantly share code, notes, and snippets.

@gerharddt
Last active September 12, 2017 05:58
Show Gist options
  • Save gerharddt/fefed19ce54ccf56ca23d77812d178df to your computer and use it in GitHub Desktop.
Save gerharddt/fefed19ce54ccf56ca23d77812d178df to your computer and use it in GitHub Desktop.
// add images to admin post object
function my_post_object_result( $title, $post, $field, $post_id ) {
if ($post->post_type == 'product') {
global $nf;
$title = '<div class="prodi" style="background-image: url(' . $nf->image(wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ), 140, 140) . ');"></div>' . $title;
$title = '<div class="prodc">' . $title . '</div>';
return $title;
}
}
add_filter('acf/fields/post_object/result', 'my_post_object_result', 10, 4);
// add images to admin post object - css
add_action('admin_head', 'fields_custom_styles');
function fields_custom_styles() {
echo '
<style type="text/css">
.ui-sortable .prodi {
background-color: #fff;
background-position: 50% 50%;
background-repeat: no-repeat;
background-size: contain;
height: 140px;
width: 140px;
}
.ui-sortable .prodc {
font-size: 11px;
overflow: hidden;
padding-bottom: 2px;
width: 140px;
}
</style>
';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment