Back to contents

JetEngine: How to Use Custom Callback to Display Information in Admin Columns

 

This tutorial will teach you to use a custom callback to display information from the meta fields in admin columns of posts within 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 custom type posts list. 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 wp-content > themes and open the folder with the theme you are currently using.

functions document

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_image( $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 meta field name from which you want to take the picture. If you need a more versatile one, check out this link.

2 Step — Add a new admin column

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

custom post types list

3 Step — Define admin column settings

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

Now it is time to go through the column settings.

post type admin column custom callback
  • Title — choose the column name displayed in the content type posts list;
  • Type — select the type of data that will be used in the column. Select the Custom Callback option;
  • Callback — insert the callback function name here;
  • Column Order — type in the value that will define the number of the column’s order;
  • Prefix and Suffix — set the text placed before or after the data in the column;
  • Is Sortable —  enable this toggle if you want to make the column sortable.

4 Step — Update the post type

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

properties post type image admin column

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