Problem with table names.

I built a new site following the WP instructions which basically turns a single blog into networked. When you do this the tables created for the first blog are NOT prefix_blog_id_tablename (e.g wp_1_posts) but are in fact prefix_tablename (i.e. wp_posts).

The front page for the Network theme contains a call to multisite_recent_posts which contains the following code:

foreach ($blogs as $blog) {

			$thumbnail = '';

			$blogOptionsTable = $wpdb->base_prefix.$blog."_options";
		  $blogPostsTable = $wpdb->base_prefix.$blog."_posts";
   		$blogPostsMetaTable = $wpdb->base_prefix.$blog."_postmeta";

Which breaks because blog 1 does not contain the blog_id in the table names.

  • aecnu

    Greetings steveatty,

    Thank you for this great question.

    Indeed Blog 1 is not supposed to show in the Network theme in which is usually installed the main site of a MultiSite network and probably most importantly because there is no Blog 1 prefix.

    WordPress uses the originally created, non prefixed databases for the main site in which you must be referring to as Blog 1.

    Below is a screen shot of a MultiSite not using Multi DB therefore the structure is exactly how WordPress makes it from stock.

    Take note there is no blog 1 prefix and therefore no blog 1 labeled tables and therefore no reference made to them - they do not exist as such. I believe it is possible your concept of how the Network theme works may not be accurate or perhaps the Network themes purpose.

    If I am missing what you are trying to say please advise and I have never seen a broken blog using this theme.

    Please advise.

    Cheers, Joe

  • Steve Atty

    I'm very aware of how the DB structure is laid out

    What I'm saying is that your code contains a bug.

    The multisite_recent_post function (in custom-functions.php) contains the following code:

    if ($how_long > 0) {
    		$blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE
    			public != '2' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0'
    			AND last_updated >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
    			ORDER BY last_updated DESC LIMIT $how_many");
    	} else {
    		$blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE
    			public != '2' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0'
    			ORDER BY last_updated DESC LIMIT $how_many");
    	}

    This will return ALL the blogs (including blog 1)

    So when this code runs:

    $blogOptionsTable = $wpdb->base_prefix.$blog."_options";
    		  $blogPostsTable = $wpdb->base_prefix.$blog."_posts";
       		$blogPostsMetaTable = $wpdb->base_prefix.$blog."_postmeta";

    which is then fed into:

    $options = $wpdb->get_results("SELECT option_value FROM
    				$blogOptionsTable WHERE option_name IN ('siteurl','blogname')
    				ORDER BY option_name DESC");
    			if ($how_long > 0) {
    				$thispost = $wpdb->get_results("SELECT ID, post_title
    					FROM $blogPostsTable WHERE post_status = 'publish'
    					AND ID > 0
    					AND post_type = 'post'
    					AND post_date >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
    					ORDER BY id DESC LIMIT 0,1");
    			} else {
    				$thispost = $wpdb->get_results("SELECT ID, post_title
    					FROM $blogPostsTable WHERE post_status = 'publish'
    					AND ID > 0
    					AND post_type = 'post'
    					ORDER BY id DESC LIMIT 0,1");
    
    			}

    If fires an error into my php error logs because it is looking for wp_1_postmeta, wp_1_posts and wp_1_options

    I could fix it by marking the root blog as not public but that seems the wrong thing to do.

    As a complete aside why is the root blog excluded from the front page?

  • aecnu

    Greetings steveatty,

    As a complete aside why is the root blog excluded from the front page?

    Why would it include the page of itself?

    I have never had any trouble with this theme nor it showing the network of sites within the network but of course I would not want it to include itself.

    Obviously because I do not understand this or see this as a bug, I cannot help you.

    I have gone ahead and alerted the lead developer to this so called "bug" and that is the end of it for me.

    Cheers, Joe

  • Steve Atty

    Oh its showing the sites - but the code is including blog id 1 (i.e. the root blog ) which can have posts but doesn't have blog_id in its table names and that is throwing errors in the php logs.

    I'm not sure what you mean about "not want it including itself" The theme is installed in the root blog and shows the recent post from all the sites as its front page. So if the root blog has posts in it (which is perfectly legal) then surely it would make sense for them to be displayed as well.

    However I'm more than happy to talk to the developer about this.

  • aecnu

    Greetings steveatty,

    Thank you for the additional feedback, it is appreciated.

    I admit that I was under the opposite impression of what is really going on to be true.

    I thought that you were having an issue because blog id 1 was not being included!

    Your last post clarified that this is not the case but the exact opposite.

    My sincere apology for misinterpreting what the issue was here.

    Waiting for the lead developer to comment on this since I have already flagged him, but indeed the issue is now clear and hopefully he will have it resolved soon.

    Cheers, Joe

  • aecnu

    Greetings Steve,

    Agreed that there are some bizarre things going on in these themes and unfortunately the original lead developers of these themes are no longer with WPMU Dev leaving the new developer left holding the bag so to speak.

    Therefore nobody to go back on or hold accountable and ask "what were you thinking when you did this?".

    I see that a new release came last night from the current lead developer, did this release by any chance resolve any of your reported issues?

    I do still have the original flag asking the lead developer to come in here, but if we can offer any relief before hand it would be great even if it involves simply consolidating the issues into one post.

    Please advise.

    Cheers, Joe

  • aecnu

    Greetings Steve,

    We have not heard back from you as to the status of this issue.

    If you are still having an issue please let us know so that we may try to get you fixed up as soon as possible by choosing to check mark this ticket as unresolved below and posting any new errors or symptoms you are noticing.

    This action will also bring your ticket up front back in plain view again within the ticket system.

    Thank you for being a WPMU Dev member!

    Cheers, Joe

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.