taxonomies other than post tags

I'm curious what sorts of edits to the Global Site Tags plugin (or the Post Indexer plugin?) would be necessary such that we can display other sitewide taxonomies instead of post tags; thanks. (It's possible, for instance, that we'd define a new global tags taxonomy such that post tags can continue to be used as normal).

Thanks,

Jim P.

  • Jim

    My understanding is that Global Site Tags displays sitewide tags, i.e., taxonomy = 'post_tag', only. We are considering a set of reserved tags that would be used globally (new taxonomies such as this are easy to register). In this way, users can continue to tag posts as they wish, and invoke our reserved tags via a separate taxonomy. Does this help? Happy to provide further info; I suspect it would be a relatively simple tweak we'd do of Post Indexer or, if it already stores all associated taxonomy metadata, Global Site Tags (which looks only for post tags).

    Thanks,

    Jim P.

  • Hoang Ngo

    Hi @Jim,

    I hope you are well today and I'm sorry about the delay.

    If that, so you must modify the plugin to make it work like your need.

    Line 259, file plugins/global-site-tags/global-site-tags.php you will see the code look like:

    $query = "
    			SELECT COUNT(*) as 'count',
    			       t.term_id,
    				   t.term_id as id,
    				   t.name,
    				   t.slug,
    				   t.term_group,
    				   tt.term_taxonomy_id,
    				   tt.taxonomy,
    				   tt.description,
    				   tt.parent,
    				   CONCAT('{$base_url}', t.slug) as 'link'
    			  FROM {$this->db->base_prefix}network_terms as t
    			 INNER JOIN {$this->db->base_prefix}network_term_taxonomy AS tt ON t.term_id = tt.term_id
    			 INNER JOIN {$this->db->base_prefix}network_term_relationships AS tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
    			 INNER JOIN {$this->db->base_prefix}network_posts AS np ON np.ID = tr.object_id AND np.BLOG_ID = tr.blog_id
    			 WHERE tt.taxonomy = 'post_tag'";

    This is the main query, for query the taxonomy, so example, if you want to change to categories, just make it like this:

    $query = "
    			SELECT COUNT(*) as 'count',
    			       t.term_id,
    				   t.term_id as id,
    				   t.name,
    				   t.slug,
    				   t.term_group,
    				   tt.term_taxonomy_id,
    				   tt.taxonomy,
    				   tt.description,
    				   tt.parent,
    				   CONCAT('{$base_url}', t.slug) as 'link'
    			  FROM {$this->db->base_prefix}network_terms as t
    			 INNER JOIN {$this->db->base_prefix}network_term_taxonomy AS tt ON t.term_id = tt.term_id
    			 INNER JOIN {$this->db->base_prefix}network_term_relationships AS tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
    			 INNER JOIN {$this->db->base_prefix}network_posts AS np ON np.ID = tr.object_id AND np.BLOG_ID = tr.blog_id
    			 WHERE tt.taxonomy = 'category'";

    Base on this, I think you can update the script and make it work with your custom taxonomy.

    If you have any issues please don't hesitate to let us know so we can assist.

    Best Regards
    Hoang

  • Jim

    I've done the above now (i.e., changed "WHERE tt.taxonomy =..." to the correct post type), and have rebuilt the Post Index. If you look here at my root site Tags page, I see a tag cloud, and when you rollover each tag you see the correct number of posts I believe, but all clicked tag links result in "Nothing found for search term(s)." I believe in past I was instructed to re-save permalinks settings, which I did, but this didn't help. Perhaps there's another issue that arises then you change the taxonomy?

    Jim P.

  • Jim

    Thank you for your reply! I can't, however, locate the tag.php template file. I read here that the wp_tag_cloud function can utilize an optional tag.php, but defaults to archive.php. This multisite is using Genesis framework, and I find archive.php in genesis > lib > structure (but no tag.php here, and no archive.php nor tag.php in my child theme). I've uploaded the Genesis archive.php here. If I'm incorrect, please let me know asap and I can upload the correct file.

    Jim P.

  • Saurabh

    Hi Jim!

    Sorry for the inconvenience. Actually, the theme files are alright.

    The individual tag pages won't load because the plugin will still look for tags by that name, instead of your custom taxonomy.

    To fix that, in the same file (plugins/global-site-tags/global-site-tags.php), at about line 341, locate this code:

    network_query_posts( array(
    			'posts_per_page' => absint( $global_site_tags_per_page ),
    			'paged'          => isset( $wp_query->query_vars['paged'] ) && $wp_query->query_vars['paged'] > 1 ? $wp_query->query_vars['paged'] : 1,
    			'tag'            => urldecode( $wp_query->query_vars['tag'] ),
    			'post_type'      => $global_site_tags_post_type != 'all'
    				? $global_site_tags_post_type
    				: $this->global_site_tags_get_post_types(),
    		) );

    We'll need to remove the query for 'tag' and add a custom taxonomy query. The modified query would be:

    network_query_posts( array(
    			'posts_per_page' => absint( $global_site_tags_per_page ),
    			'paged'          => isset( $wp_query->query_vars['paged'] ) && $wp_query->query_vars['paged'] > 1 ? $wp_query->query_vars['paged'] : 1,
    			// 'tag'            => urldecode( $wp_query->query_vars['tag'] ),
    			'post_type'      => $global_site_tags_post_type != 'all'
    				? $global_site_tags_post_type
    				: $this->global_site_tags_get_post_types(),
    			'tax_query'	=> array(
    				array(
    					'taxonomy'	=> '{your_custom_taxonomy}',
    					'field'		=> 'slug',
    					'terms'		=> urldecode( $wp_query->query_vars['tag'] ),
    					)
    				),
    		) );

    Replace {your_custom_taxonomy} and it will then list your posts correctly.

    Although I have tested it, do let me know how that works out for you!

    Best

    Saurabh