I have a simple foreach loop that outputs an ordered list from a CPT 'post_subscribers' and an associated meta key called 'project'.
$theposts = get_posts( array(
'post_type' => 'post_subscriber',
'post_status' => 'publish',
'numberposts' => -1,
) );
echo '<ol>';
foreach( $theposts as $p ):
$project_name = get_post_meta($p->ID, 'project', true);
echo '<li class="mb-3">';
echo get_the_title($project_name);
echo '</li>';
endforeach;
echo '</ol>';
echo 'Total projects - '. count($theposts)."</br>";
My list will generate:
- Project title one
- Project title two
- Project title two
- Project title two
- Project title three
- Project title one
Total projects - 6
Q) Within my generated ordered list there are several exact matching '$project_name'(s). How can I count the multiple matching '$project_name'(s) entries and display the count for each of them as a separate resultresults? (As I have 300+ in my generated list).
EG result: There are 3 projects with the name 'Project title two'.
It seems like a relatively simple task but I can't get my head around it? Many thanks in advance :-)