Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Last active April 20, 2026 17:40
Show Gist options
  • Select an option

  • Save Crocoblock/b5b6ef62436b01ce23bc60d1a554a85b to your computer and use it in GitHub Desktop.

Select an option

Save Crocoblock/b5b6ef62436b01ce23bc60d1a554a85b to your computer and use it in GitHub Desktop.
Get JetEngine Related Items programmatically / Update related items / Get/Update relation meta
@AndresCarignano
Copy link
Copy Markdown

So helpful!

@kankadev
Copy link
Copy Markdown

kankadev commented May 23, 2024

Very helpful. Thanks.

I use the last action. It works for the initial connecting but not if I change the meta field value of a existing relation.

My usecase is:

I have a "Job CCT". The relation is one to many between Job CCT and user. There is one job and many people can apply for it. The relation has got a meta field called "status" where I select "applied", "meeting", "canceled" etc.

I want to fire actions if this meta field value changes. If the status changes from applied to canceld, I want to send an e-mail.

Which hook can I use for this?

Thank you very much.

EDIT:

I think I found a solution:

add_action('jet-engine/relation/update-all-meta/after', function ($parent_object, $child_object, $new_meta, $old_meta) {
    write_log('jet-engine/relation/update-all-meta/after');

    if (is_array($new_meta) && isset($new_meta['status'])) {

        $relation = jet_engine()->relations->get_active_relations(13);
        $user_rows = $relation->get_children($parent_object, 'all');
        $user_id = 0;
        if (is_array($user_rows) && count($user_rows) > 0)
            $user_id = (int)$user_rows[0]['child_object_id'];

        if ($user_id > 0):
            $user = get_user_by('ID', $user_id);
            if ($user instanceof WP_User):
                $user_email = $user->user_email;
                $user_name = $user->display_name;
                $user_first_name = $user->first_name;
                $user_last_name = $user->last_name;

                switch ($new_meta['status']):
                    case 'in planning':

                        break;
                    case 'planned':

                        wp_mail($user_email, 'Planned', 'Planned');
                        break;

                    case 'canceled':

                        break;

                    case 'realized':

                        break;
                endswitch;
            endif;
        endif;

    }
}, 12, 4);

@moxet
Copy link
Copy Markdown

moxet commented May 27, 2024

Very helpful, i was building a CRM in which the client need to upload leads from excel and assign it directly to agents. The assignment is relation but not to make agent as post author; thus this 3 lines of codes help a lot.

Thanks

@Mohsin-Shakeel
Copy link
Copy Markdown

Very Helpful, Is it possible to append multiple items in same parent object or isnerted psot id using loop. I ahve multiple ods in array but update method connect only last one...

@morosmo
Copy link
Copy Markdown

morosmo commented Apr 25, 2025

Hi folks,
I'm using the jet-engine/relation/update/after action to add an ID to a meta field when a relation is connected. However, when the relation is disconnected, the ID doesn't get removed.

Is there any JetEngine action hook that runs specifically when a relation is disconnected?

@davidhamilton994
Copy link
Copy Markdown

Yo estuve ayer analizando términos y condiciones de diferentes operadores y comparando estrategias de conversión de bonos, y terminé con la cabeza tan saturada de porcentajes y letras pequeñas que necesitaba un respiro total. Un colega me recomendó entrar en casoola casino y aproveché los bonos para España que tienen ahora. Empecé con mala racha, pero en la última jugada gané un premio que me cambió el ánimo. ¡Es ideal para desconectar tras descifrar la letra pequeña de las promociones!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment