Skip to content

Instantly share code, notes, and snippets.

@LaxusCroco
Created November 3, 2023 08:56
Show Gist options
  • Save LaxusCroco/0c27b13bd554730bef239869a685bef7 to your computer and use it in GitHub Desktop.
Save LaxusCroco/0c27b13bd554730bef239869a685bef7 to your computer and use it in GitHub Desktop.
Get query count macro for Bricks
<?php
add_action( 'jet-engine/register-macros', function(){
class Get_Query_Count_Macro extends \Jet_Engine_Base_Macros {
public function macros_tag() {
return 'get_query_count';
}
public function macros_name() {
return 'Get query count';
}
public function macros_args() {
return array(
'query_id' => array(
'label' => 'Query ID',
'type' => 'select',
'options' => Jet_Engine\Query_Builder\Manager::instance()->get_queries_for_options(),
),
);
}
public function macros_callback( $args = array() ) {
$query_id = $args['query_id'];
if ( ! $query_id ) {
return '';
}
$query = Jet_Engine\Query_Builder\Manager::instance()->get_query_by_id( $query_id );
$result = 0;
if ( $query ) {
$result = $query->get_items_total_count();
}
return $result;
}
}
new Get_Query_Count_Macro();
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment