How can I auto-assign the first image file for a listing as the featured image whenever a directory listing is added/updated?

How Can We Help?
< Back
You are here:

Use the following code:
add_action(‘drts_entity_create_post_entity_success’, ‘my_drts_entity_create_post_entity_succes’, 10, 2);
add_action(‘drts)_entity_create_post_entity_succes’, 10, 2);

function my_drts_entity_create_post_entity_succes($bundle, $entity) {
if ($bundle->type === ‘directory__listing’) {
if ($value = $entity->getSingleFieldValue(‘directory_photos’)) {
set_post_thumbnail($entity->getId(), $value[‘attachment_id’]);

Previous Can one display blog posts for the listing author on the authors listing page?
Next How can I display portions of a listing in a sidebar?
Table of Contents