GithubHelp home page GithubHelp logo

Comments (12)

gavinhewitt avatar gavinhewitt commented on August 15, 2024 1

Here: https://support.advancedcustomfields.com/forums/topic/acf-countrycitystate-field/

from acf-city-selector.

Beee4life avatar Beee4life commented on August 15, 2024

Might be a good addition... will look into it...

I hope to push everything to master somewhere early this week.

from acf-city-selector.

Beee4life avatar Beee4life commented on August 15, 2024

BTW how did you find it ? Didn't really promote it yet...

from acf-city-selector.

Beee4life avatar Beee4life commented on August 15, 2024

All issues I mentioned there are fixed (afaik).

from acf-city-selector.

gavinhewitt avatar gavinhewitt commented on August 15, 2024

Somewhat unrelated question (I'm pretty new to this ACF thing, hope you can help):

I need to display an overview of all provinces (with total post count) and include a list of all cities that have posts attached (also with count, see image). How would you go about this with ACF fields?

image

from acf-city-selector.

Beee4life avatar Beee4life commented on August 15, 2024

This is a rough idea....

$post_args            = array(
    'post_type'      => 'post_type',
    'posts_per_page' => 999,
    'meta_query'     => array(
        array(
            'key'     => 'sd_city_selector',
            'compare' => 'EXISTS',
        ),
    ),
);
$posts_with_city_info = get_posts( $post_args );

if ( false != $posts_with_city_info ) {
    $states_array = false;
    $city_info    = false;
    foreach ( $posts_with_city_info as $post ) {
        $field_value    = get_field( 'sd_city_selector', $post->ID );
        $city_info[]    = $field_value;
        $states_array[] = $field_value[ 'stateName' ];
    }
    if ( $states_array ) {
        $no_double_states = array_unique( $states_array );
        foreach ( $no_double_states as $state ) {
            echo $state;
            // get all array keys from $city_info where stateName == $state
            // count unique values
        }
    }
}

I added comments where you still need to do some work, but i've been working too long today already :)

from acf-city-selector.

gavinhewitt avatar gavinhewitt commented on August 15, 2024

Ja top, hier kan ik wel iets mee.

Thanks!

from acf-city-selector.

Beee4life avatar Beee4life commented on August 15, 2024

Please post the result (if you found one), so someone else can also use it in case of need.

from acf-city-selector.

Beee4life avatar Beee4life commented on August 15, 2024

@gavinhewitt v0.1 has been released (and it has some minor fixes)

from acf-city-selector.

SmallBizon avatar SmallBizon commented on August 15, 2024

Thank you guys, for your ideas. I finished your code. May be not best, but works for me.

$post_args            = array(
    'post_type'      => 'clinic',
    'posts_per_page' => 999,
    'meta_query'     => array(
        array(
            'key'     => 'sd_city_selector',
            'compare' => 'EXISTS',
        ),
    ),
);
$posts_with_city_info = get_posts( $post_args );

if ( false != $posts_with_city_info ) {
    $states_array = false;
    $city_info    = false;
    foreach ( $posts_with_city_info as $post ) {
        $field_value    = get_field( 'sd_city_selector', $post->ID );
        $city_info[]    = $field_value;
        $cities_array[] = $field_value[ 'cityName' ];
        $states_array[] = $field_value[ 'stateName' ];
    }
    
    $clinics_in_city_counter = array_count_values($cities_array);
    $clinics_in_state_counter = array_count_values($states_array);

    if ( $states_array ) {

        $no_double_states = array_unique( $states_array );
        foreach ( $no_double_states as $state ) {
          echo "<h3>" . $state . "</h3>";     
          echo $clinics_in_state_counter[$state]." клиник<br />";
          foreach ( $city_info as $address_arr){
                    
                    if ($address_arr['stateName']==$state){
                        $cities_of_state[]=$address_arr['cityName'];
                    } 
                }
        $no_double_cities = array_unique( $cities_of_state );

       echo "<ul>";
       foreach ($no_double_cities as $city) {
            echo "<li>" . $city . " " . $clinics_in_city_counter[$city]."</li>";

        }
        echo "</ul>";
        $cities_of_state=array();
        $no_double_cities=array();
        }
    }
}

from acf-city-selector.

Beee4life avatar Beee4life commented on August 15, 2024

Thank you for this, I will try to take a look at it when i have some time, but very busy this month.

from acf-city-selector.

Beee4life avatar Beee4life commented on August 15, 2024

This request has been outstanding for more than 2 years, but I can finally say this is now incorporated in the plugin. You can now set a default country, from the countries you have in your database.

So closing this topic now (finally) :)

from acf-city-selector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.