Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Last active February 7, 2024 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Crocoblock/2d97b335cd5ab2c7d4f6008e90d8c097 to your computer and use it in GitHub Desktop.
Save Crocoblock/2d97b335cd5ab2c7d4f6008e90d8c097 to your computer and use it in GitHub Desktop.
JetEngine. Register and process custom contexts.
<?php
/**
* Here we're regsitering our context to show in allowed context option
*/
add_filter( 'jet-engine/listings/allowed-context-list', function( $context_list ) {
$context_list['_my_parent_object'] = 'Parent Property';
$context_list['_my_child_object'] = 'Child Attraction';
return $context_list;
} );
/**
* Here we're propcessing cstom context '_my_parent_object' when it selected by user
*/
add_filter( 'jet-engine/listings/data/object-by-context/_my_parent_object', function() {
$current_object = jet_engine()->listings->data->get_current_object();
if ( ! isset( $current_object->parent_object_id ) ) {
return false;
}
$object = get_post( $current_object->parent_object_id );
$object->post_status = get_post_meta( $object->ID, 'prop_coordinates', true );
return $object;
} );
/**
* Here we're propcessing cstom context '_my_child_object' when it selected by user
*/
add_filter( 'jet-engine/listings/data/object-by-context/_my_child_object', function() {
$current_object = jet_engine()->listings->data->get_current_object();
if ( ! isset( $current_object->child_object_id ) ) {
return false;
}
$object = get_post( $current_object->child_object_id );
$object->post_status = get_post_meta( $object->ID, 'coordinates', true );
return $object;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment