Skip to content

Instantly share code, notes, and snippets.

@donaldG
Created December 12, 2019 15:58
Show Gist options
  • Save donaldG/3364b71976891611b173a32e38162cd6 to your computer and use it in GitHub Desktop.
Save donaldG/3364b71976891611b173a32e38162cd6 to your computer and use it in GitHub Desktop.
<?php
public function render_summary_report_widget() {
$not_hidden_queries = array(
'companies-dont-test' => array(
'post_type' => 'company',
'posts_per_page' => -1,
'suppress_filters' => 0,
'meta_query' => array(
array(
'key' => 'animal_testing_policy',
'value' => 'Does Not Test',
'compare' => 'LIKE',
),
array(
'key' => 'hide_company_from_users',
'value' => 0,
'compare' => 'LIKE',
),
),
),
'companies-do-test' => array(
'post_type' => 'company',
'posts_per_page' => -1,
'suppress_filters' => 0,
'meta_query' => array(
array(
'key' => 'animal_testing_policy',
'value' => 'Does Test',
'compare' => 'LIKE',
),
array(
'key' => 'hide_company_from_users',
'value' => 0,
'compare' => 'LIKE',
),
),
),
'companies-working-for-regulatory-change' => array(
'post_type' => 'company',
'posts_per_page' => -1,
'suppress_filters' => 0,
'meta_query' => array(
array(
'key' => 'animal_testing_policy',
'value' => 'Working for Regulatory Change',
'compare' => 'LIKE',
),
array(
'key' => 'hide_company_from_users',
'value' => 0,
'compare' => 'LIKE',
),
),
),
'undefined-companies' => array(
'post_type' => 'company',
'posts_per_page' => -1,
'suppress_filters' => 0,
'meta_query' => array(
array(
'key' => 'animal_testing_policy',
'value' => 'Working for Regulatory Change',
'compare' => 'NOT LIKE',
),
array(
'key' => 'animal_testing_policy',
'value' => 'Does Test',
'compare' => 'NOT LIKE',
),
array(
'key' => 'animal_testing_policy',
'value' => 'Does Not Test',
'compare' => 'NOT LIKE',
),
array(
'key' => 'hide_company_from_users',
'value' => 0,
'compare' => 'LIKE',
),
),
),
'vegan-companies' => array(
'post_type' => 'company',
'posts_per_page' => -1,
'suppress_filters' => 0,
'meta_query' => array(
array(
'key' => 'animal_testing_policy',
'value' => 'Does Not Test',
'compare' => 'LIKE',
),
array(
'key' => 'vegan',
'value' => 1,
'compare' => 'LIKE',
),
array(
'key' => 'hide_company_from_users',
'value' => 0,
'compare' => 'LIKE',
),
),
),
);
$hidden_queries = array(
'companies-dont-test' => array(
'post_type' => 'company',
'posts_per_page' => -1,
'suppress_filters' => 0,
'meta_query' => array(
array(
'key' => 'animal_testing_policy',
'value' => 'Does Not Test',
'compare' => 'LIKE',
),
array(
'key' => 'hide_company_from_users',
'value' => 1,
'compare' => 'LIKE',
),
),
),
'companies-do-test' => array(
'post_type' => 'company',
'posts_per_page' => -1,
'suppress_filters' => 0,
'meta_query' => array(
array(
'key' => 'animal_testing_policy',
'value' => 'Does Test',
'compare' => 'LIKE',
),
array(
'key' => 'hide_company_from_users',
'value' => 1,
'compare' => 'LIKE',
),
),
),
'companies-working-for-regulatory-change' => array(
'post_type' => 'company',
'posts_per_page' => -1,
'suppress_filters' => 0,
'meta_query' => array(
array(
'key' => 'animal_testing_policy',
'value' => 'Working for Regulatory Change',
'compare' => 'LIKE',
),
array(
'key' => 'hide_company_from_users',
'value' => 1,
'compare' => 'LIKE',
),
),
),
'undefined-companies' => array(
'post_type' => 'company',
'posts_per_page' => -1,
'suppress_filters' => 0,
'meta_query' => array(
array(
'key' => 'animal_testing_policy',
'value' => 'Working for Regulatory Change',
'compare' => 'NOT LIKE',
),
array(
'key' => 'animal_testing_policy',
'value' => 'Does Test',
'compare' => 'NOT LIKE',
),
array(
'key' => 'animal_testing_policy',
'value' => 'Does Not Test',
'compare' => 'NOT LIKE',
),
array(
'key' => 'hide_company_from_users',
'value' => 1,
'compare' => 'LIKE',
),
),
),
'vegan-companies' => array(
'post_type' => 'company',
'posts_per_page' => -1,
'suppress_filters' => 0,
'meta_query' => array(
array(
'key' => 'animal_testing_policy',
'value' => 'Does Not Test',
'compare' => 'LIKE',
),
array(
'key' => 'vegan',
'value' => 1,
'compare' => 'LIKE',
),
array(
'key' => 'hide_company_from_users',
'value' => 1,
'compare' => 'LIKE',
),
),
),
);
$i = 1;
$not_hidden_post_counts = array();
foreach ( $not_hidden_queries as $query_args ) {
$query = new \WP_Query( $query_args );
$post_label = 'Does Not Test';
$not_hidden_post_counts[] = $query->post_count;
if ( 2 === $i ) {
$post_label = 'Does Test';
} elseif ( 3 === $i ) {
$post_label = 'Working For Regulatory Change';
} elseif ( 4 === $i ) {
$post_label = 'Undefined';
} elseif ( 5 === $i ) {
$post_label = 'Vegan Companies';
}
echo esc_html( $post_label . ': ' . $query->post_count ) . '<br />';
$i++;
}
$i = 1;
$hidden_post_counts = array();
foreach ( $hidden_queries as $query_args ) {
$query = new \WP_Query( $query_args );
$post_label = 'Does Not Test (hidden)';
$hidden_post_counts[] = $query->post_count;
if ( 2 === $i ) {
$post_label = 'Does Test (hidden)';
} elseif ( 3 === $i ) {
$post_label = 'Working For Regulatory Change (hidden)';
} elseif ( 4 === $i ) {
$post_label = 'Undefined (hidden)';
} elseif ( 5 === $i ) {
$post_label = 'Vegan Companies (hidden)';
}
echo esc_html( $post_label . ': ' . $query->post_count ) . '<br />';
$i++;
}
$i = 1;
$combined_companies = array_combine( $not_hidden_post_counts, $hidden_post_counts );
foreach ( $combined_companies as $key => $val ) {
$post_label = 'Does Not Test (total)';
if ( 2 === $i ) {
$post_label = 'Does Test (total)';
} elseif ( 3 === $i ) {
$post_label = 'Working For Regulatory Change (total)';
} elseif ( 4 === $i ) {
$post_label = 'Undefined (total)';
} elseif ( 5 === $i ) {
$post_label = 'Vegan Companies (total)';
}
echo esc_html( $post_label . ' :' . ( $key + $val ) ) . '<br />';
$i++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment