Forked from ihslimn/gist:aeb76a778ed44d32faf640f4d3bda8ea
Last active
April 30, 2024 11:06
-
-
Save Crocoblock/466cac243422028bc0ac22ef901dcd38 to your computer and use it in GitHub Desktop.
Get properties from query macro
This file contains hidden or 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 | |
//OBSOLETE | |
//Use Query Results built-in macro instead | |
//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