Skip to content

Instantly share code, notes, and snippets.

@ihslimn
Created June 22, 2022 16:07
Show Gist options
  • Save ihslimn/c8dc041eb75d4567db1a25293d687372 to your computer and use it in GitHub Desktop.
Save ihslimn/c8dc041eb75d4567db1a25293d687372 to your computer and use it in GitHub Desktop.
add_filter( 'jet-engine/listings/macros-list', 'register_current_post_parent_macro' );
function register_current_post_parent_macro( $macros_list ) {
$macros_list['current_post_parent'] = array(
'label' => 'Current post parent (current post ID if no parent)',
'cb' => '_get_current_post_parent',
);
return $macros_list;
}
function _get_current_post_parent( $field_value = null, $args = null ) {
$current_object = jet_engine()->listings->data->get_current_object();
$class = get_class( $current_object );
$result = 'not a post';
if ( 'WP_Post' == $class ) {
if ( $current_object->post_parent ) {
$result = $current_object->post_parent;
} else {
$result = $current_object->ID;
}
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment