Created
June 22, 2022 16:07
-
-
Save ihslimn/c8dc041eb75d4567db1a25293d687372 to your computer and use it in GitHub Desktop.
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
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