In wordpress, you can calculate and output how many records are contained in a certain category. But I have a “download” field in each entry. How do I calculate the total number of filled fields in all records and output this figure to the frontend?
Example for post
function tp_catpostcount($atts) {
extract(shortcode_atts(array(
"id" => ''
), $atts));
$post_count = get_category($id)->category_count;
$cat_name = get_category($id)->name;
$cat_slug = get_category($id)->slug;
return ''.$post_count.'';
}
add_shortcode('cpc', 'tp_catpostcount');
There isn’t any way to do this in WP directly. You would need to do a WP_Term_Query that includes a meta_query looking for your field name that is not an empty value.
I am far from programming. Can you show an example? Thanks.