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
    • Site Builder, Child of Zeus

    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.

  • Jim
    • Site Builder, Child of Zeus

    Yes, sure would appreciate his timely response. This could possibly be an additional feature of the Global Site Tags plugin (again, not sure if all taxonomies captured via Post Indexer), or we may customize on our end with his recommendations.

  • Jim
    • Site Builder, Child of Zeus

    Yes, I am looking for a way to use Global Site Tags (whether via widget or Tags page) to show taxonomies other than post tags; we will probably define a new custom global taxonomy for this purpose.

    Many thanks!

    Jim P.

  • Hoang Ngo
    • Code Slayer

    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
    • Site Builder, Child of Zeus

    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.

  • Hoang Ngo
    • Code Slayer

    Hi @jim,

    I hope you are well today.

    The update is for global site tags plugin, when you place the global tag widget, instead of getting post tags, it will get the custom taxonomy.

    Look at the url, that is the tag page, not custom taxonomy. So I think the issue is in your tag.php template file. Can you please upload the file so I can have a review ?

    Best Regards,

    Hoang

  • Jim
    • Site Builder, Child of Zeus

    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
    • New Recruit

    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

  • Jim
    • Site Builder, Child of Zeus

    Ah, many thanks! I’ve edited code and quickly tested, and so far it works just great! Well done. If you don’t mind leaving this ticket open for awhile, we’ll more fully test, but for now I think you’ve solved my problem.

    Regards,

    Jim P.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.