Back to contents

JetEngine: How to Use Custom Callback to Display Image in Admin Column

 

From this tutorial you will be able to learn how to use a custom callback to display some information from the meta fields in admin columns of posts of custom post type lists created with JetEngine.

It is possible to display the content from the meta fields in admin columns with the help of a custom callback function provided by the JetEngine plugin. Let’s assume, you need to display the picture from the Media meta field in the list of your custom type posts. This tutorial will show you how to do it.

1 Step — Add the code

Open the file manager on your PC and find the folder with WordPress files. Proceed to htdocs > wp-content > themes and open the folder with the theme you are currently using.

Use the Notepad app to open the functions.php file and insert the following code:

/*
* Show image by stored image ID
* $meta_key - custom field to get image from
* $size - image size to show
*/
function jet_admin_column_date( $column, $post_id ) {
$meta_key = '_image';
$image_id = get_post_meta( $post_id, $meta_key, true );
$size = 'thumbnail';
if ( ! $image_id ) {
return '--';
} else {
return wp_get_attachment_image( $image_id, $size );
}
}

It is a specialized piece for image inserting. Pay attention, that instead of “_image” you have to insert the name of the meta field that you want to take the picture from. If you need a more versatile one – check out this link.

2 Step — Add a new admin column

Now, go to your website’s dashboard and open the JetEngine > Post Types section. Click on the needed post type to edit it or choose the “Edit” option.

Post Types section in the WP Dashboard

When the settings block opens, scroll down to the Admin Columns and click the “Add New” button.

adding new admin column

3 Step — Define admin column settings

Now it is time to go through the column settings.

  • Title. This is how the column will be named in the content type posts list;
  • Type. Here you can choose the type of data that will be used in the column. Select the Custom Callback option;
  • Callback. You have to insert the callback function name here;
  • Column Order. The number you type in here will define the number of the column’s order;
  • Prefix and Suffix. The text you type in here will be placed before or after the data in the column;
  • Is Sortable. If you want to make the column sortable – enable this toggle.
setting admin column features

5 Step Finally, click the “Update Post Type” button and go to the custom post type in the WP Dashboard to view a new Image admin column.

view a new Image admin column

A great job! Now you know how to display the data from the meta fields, media files, in particular, using the callback option of JetEngine.