Home Forums ACF PRO Multisite blog list ordered by options page value


Multisite blog list ordered by options page value

  • I have been trying to create a list of subsite links on my main site using an ACF options page value get_field( 'nn_city_name', 'option' ); as the text for each link. I can get a working list, but my attempts to sort the list by nn_city_name all result in errors.

    Here’s my function:

    function x_list_sites() {
      $subsites = get_sites(
          'site__not_in' => '1',
          // 'orderby' => 'domain',
      if ( !empty( $subsites ) ) {
        echo '<h3>Nerd Nite Cities</h3>';
        echo '<ul class="subsites">';
        foreach ( $subsites as $subsite ) {
          $subsite_id = get_object_vars( $subsite )[ 'blog_id' ];
          switch_to_blog( $subsite_id );
          $subsite_name = get_field( 'nn_city_name', 'option' );
          $subsite_link = get_blog_details( $subsite_id )->siteurl;
          echo '<li class="site-' . $subsite_id . '"><a href="' . $subsite_link . '">' . $subsite_name . '</a></li>';
        echo '</ul>';

    Here’s a test page that puts the list in the sidebar:


    1. I feel like I should be able to do some kind of array_push() to add nn_city_name to $subsites so that I can sort by nn_city_name, but my attempts have failed.
    2. 'orderby' => ‘domain’ gets most of the subsites into correct order, but you run into problems with a subdomain like “nyc” for “New York”.

    Thanks in advance!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.