Created
May 6, 2022 13:52
-
-
Save ihslimn/aeb76a778ed44d32faf640f4d3bda8ea to your computer and use it in GitHub Desktop.
Get properties from query macro
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 Get properties from query macro | |
add_filter( 'jet-engine/listings/macros-list', 'register_query_items_macro' ); | |
function register_query_items_macro( $macros_list ) { | |
$macros_list['get_props_from_query'] = array( | |
'label' => 'Get properties from query', | |
'cb' => 'get_props_from_query_macro', | |
'args' => array( | |
'query_id' => array( | |
'label' => 'Query ID', | |
'type' => 'select', | |
'options' => Jet_Engine\Query_Builder\Manager::instance()->get_queries_for_options(), | |
), | |
'property' => array( | |
'label' => 'Property', | |
'type' => 'text', | |
'default' => '', | |
), | |
), | |
); | |
return $macros_list; | |
} | |
function get_props_from_query_macro( $field_value = null, $args = null ) { | |
$args = explode( '|', $args ); | |
$query_id = $args[0]; | |
$property = $args[1]; | |
if ( ! $query_id || ! $property ) { | |
return; | |
} | |
$query = Jet_Engine\Query_Builder\Manager::instance()->get_query_by_id( $query_id ); | |
$result = 'not-found'; | |
if ( $query ) { | |
$query_items = $query->get_items(); | |
if ( ! empty( $query_items ) ) { | |
$properties_array = array_column( $query_items, $property ); | |
$result = array_unique( $properties_array ); | |
$result = implode( ',', $result ); | |
} | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment