so i have multiple posts. two categories. some posts made by an author are only in one category. but other author posts might be in both categories. i need to remove duplicates. i can only have one author post at a time. so i was just going to default to the more important (shop post and not service post) category of the two and list that post.
but im puzzled on how to go about doing so.
Here is how I obtained my data and process it for output:
$allPosts = get_post_type_data('archive', 'all');
for($i = 0; $i < count($allPosts); $i++){
if($allPosts[$i]['post_type'] == 'antique-shops'){
$shopData[] = $allPosts[$i];
}
if($allPosts[$i]['post_type'] == 'member-dealers'){
$memberData[] = $allPosts[$i];
}
if($allPosts[$i]['post_type'] == 'services'){
$serviceData[] = $allPosts[$i];
}
}
$business = array_merge((array)$shopData, (array)$serviceData);
function cmp($a, $b){
return strcmp(rewrite_name($a['custom']['wpcf-business-contact'][0]), rewrite_name($b['custom']['wpcf-business-contact'][0]));
}
usort($business, "cmp");
for($i = 0; $i < count($business); $i++){
if($i % 2){
$className = 'odd';
} else{
$className = 'even';
}
$check = check_member($business[$i]['custom']['wpcf-business-contact'][0], $memberData);
if($check[0] == 'true'){
echo display_listing('member-dealers', $check[1], $business[$i], $className);
}
}
So after getting all the data, I merge Antique Shops and Services together in one array and leave members to have their own data array.
Then for each of the business data items, i check the business contact to see if it matches with the member data.
$check
returns array values. $check[0]
= true/false $check[1]
= array of data pertaining to the particular member.
display_listing()
just takes the data entered per business/member and outputs it.
I'm thinking I need to check for duplicates right before the business or service is checked against the members data.
Each antique shop or service has a business contact: $business[$i]['custom']['wpcf-business-contact'][0]
which is used to check if that business contact exists as a member.
so if $business[$i]['custom']['wpcf-business-contact'][0]
belongs to both a antique shop AND a service, remove the service data pertaining to that person from the array.
I have tried this (inside the loop):
if(($key = array_search($business[$i]['custom']['wpcf-business-contact'][0], $business)) !== false){
unset($business[$key]);
}
Any useful guidance on removing duplicates in this scenario?