WordPress.org

Ready to get started?Download WordPress

Forums

blog_details->blogname is wonky (8 posts)

  1. raskull
    Member
    Posted 4 years ago #

    $blog_details->blogname

    Can some one tell me why the blogname here sorts by the end of the url (my-new-site), instead of the the blog title (My New Site)?

    I am trying list all blogs in the network -- not so hard. Listing in alpha order by title (rather than "blogname"), not so easy.

    The list should sort like this:
    Apple Site (url/xpple-site)
    Beta Blog (url/betablog)
    Cats Dogs Rats (url/animal-freak)

    But it sorts like this:
    Cats Dogs Rats (url/animal-freak)
    Beta Blog (url/betablog)
    Apple Site (url/xpple-site)

    Additionally, in admin when searching by blog name, the query Cats Dogs Rats returns empty. But the query animal freak returns a result.

    Summary: why doesn't blog_details have blogtitle field?

  2. becasue blogname is actually that URL string? :)

    Sort by title is a wee bit different. I can't remember if List All redux (in this post here) will do it or not.

  3. raskull
    Member
    Posted 4 years ago #

    List All and others work, but with a TON of code, for what really should be achievable in two lines... But the two-line versions I've found have the above problem... OK I'll try to write in in five lines, but, seriously, what we need is:
    $blog_details->blogtitle

  4. And the internal function is this:
    http://wpmututorials.com/how-to/return-a-list-of-sites-on-the-network/

    But hey, if you want to expand on that so it's built-in to core, and then you can call it with a couple lines, please submit that trac ticket. :)

  5. raskull
    Member
    Posted 4 years ago #

    Alrighty then... here is my solution (below), cobbled together from various sources*.

    It is my understanding that this db query has a lot of overhead (and that this is the reason get_blog_list has been deprecated). Is that correct?.

    And that something like WP-Cache does not solve the problem?

    Are plugins like List-All and Listem doing something differently (and better) for the query?

    Now I'm off to study the Transients API. Assuming that it is a viable solution, if anyone can properly wrap this code into it, I would much appreciate it! If it's not, then please, for the love of god, tell me the solution!

    <?php
    // creates an alphabetical multisite list by blog title
    global $wpdb;
    $query = "SELECT blog_id FROM " . $wpdb->base_prefix . "blogs WHERE spam != '1' AND archived != '1' AND deleted != '1' AND public = '1' ORDER BY path";
    $allsites = $wpdb->get_results($query);
    $sitelist = array();
    foreach ($allsites as $thissite) {
    	$alldetails = get_blog_details($thissite->blog_id);
    	// here is everything contained in the blog details: blog_id, site_id, domain, path, registered, last_updated, public, archived, mature, spam, deleted, lang_id, blogname, siteurl, post_count
    	$thesedetails = array(
    	// but we only need these two for our current purposes
    	thispath=>$alldetails->path,
    	thisname=>$alldetails->blogname
    	);
    	array_push($sitelist, $thesedetails);
    }
    	foreach ($sitelist as $key=>$row) {
    		$thispath[$key] = $row['thispath'];
    		$thisname[$key] = strtolower($row['thisname']);
    	}
    array_multisort($thisname, SORT_ASC, $sitelist);
    echo '<ul>';
    foreach ($sitelist as $key=>$value )  {
    	echo '<li><a href="' . $sitelist[$key][thispath] . '">' . $sitelist[$key][thisname] . '</a></li>';
    }
    echo '</ul>';
    ?>

    *Thanks:

    I got the syntax for pulling out the details for sorting from Deanna's blog_topics plugin.

    I got the query and learned of the details from Eric.

  6. raskull
    Member
    Posted 4 years ago #

    It occurs to me that I can leave out ORDER BY path in the db query, as I sort it after that anyway. Does that save some system brain cells?

  7. raskull
    Member
    Posted 4 years ago #

    Just one more thought:

    I think there are two separate issues here:

    One issue is that if blogname were stored in the wp_blogs table then it would be easy to get_blog_list with ORDER BY blogname. (If I had any idea how to "submit a trac ticket" I would! At the very least, admin needs this functionality.)

    The other issue, I think, is that apparently we shouldn't even be querying the db like this when we have 100+ or 1000+ blogs. Even with transients api. As Ryan "Kill Them Entirely" says in the trac ticket "That list could exceed the typical memcached object size limit. I'm not sure a transient will work here."

    I can't imagine that I'm the only person on the planet who wants to search/sort/list my multisite network (aka mu blogs) by site name (title) without bringing the world to its knees...

  8. Trac ticket - http://core.trac.wordpress.org/newticket

    Login with the same credentials you use here. Enjoy.

Topic Closed

This topic has been closed to new replies.

About this Topic