'Display selected values with summary from dropdown control
I have a dropdown select (country_project) with some countries in a custom post type (project). You can choose 1 value. I want to create a comma-separated list with all values chosen in all posts, once. Non-chosen values are not displayed. So the script should echo:
France, Japan, Maroc, Australia
And for the same list, I want to have the number of different countries chosen. So in the example above the output now should be 4.
So I can create something like:
There are 4 countries presented: France, Japan, Maroc, Australia
How do I do this?
Almost too embarrased to share, but this is what I got so far. With this I thought to create the list with the selected countries in all posts and display them by their name. If I will get this to work, I will see if I can get a number out of that as well. step by step. But as you all probably will understand, except me :) this doesn't work.
$args = array(
'numberposts' => -1,
'post_type' => 'project',
);
$list_countries_projects = get_field( 'country_project' , $args );
if( count($list_countries_projects)){
foreach($list_countries_projects as $k=>$list_countries_project){
if($k) echo ', ';
echo $list_countries_project;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
