Last active
February 7, 2024 21:48
-
-
Save Crocoblock/2d97b335cd5ab2c7d4f6008e90d8c097 to your computer and use it in GitHub Desktop.
JetEngine. Register and process custom contexts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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