Skip to content

eficklin/term-activity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Term Activity Maps

WP core happily provides a current count of posts per taxonomy term. This plugin builds on that by calculating a snapshot of post counts over the past 3, 30, and 90 day periods and storing it as a serialized array in term meta.

array (
  'generated_at' => 1661192822,
  'periods' =>
  array (
    0 =>
    array (
      'days_prior' => 3,
      'count' => 11,
    ),
    1 =>
    array (
      'days_prior' => 30,
      'count' => 25,
    ),
    2 =>
    array (
      'days_prior' => 90,
      'count' => 44,
    ),
  ),
)

Publishing, unpublishing, or changing term relationships will trigger an update of the term's activity snapshot. A helper class provides some utility functions for getting and displaying the activity maps.

This plugin is a code sample, purposely bare-bones to demonstrate a bit of coding style and thought process. If you find the ideas here useful, by all means, copy away! However, this is not production ready code.

This plugin was developed on the current (as of this writing) version of WP (6.1.1). To run simply activate, add or remove some category terms from a post. You should see the activity map in the term's meta. A quick invocation of wp term meta list [tid] should do the trick.

Why?

A busy site with an aggressive recirculation strategy might need a little more insight into the posts tagged with a certain taxonomy term beyond what the core-provided counts can offer.

Consider:

  • a term has lots of posts but they're not current, perhaps related to an election or a sporting event; likely not a great candidate for recirculation but a simple count of the posts won't tell you that
  • an editor might need a certain minimum number of posts for a recirculation module (a listicle, maybe?); when it comes to the underlying implementation, grabbing everything could be too much, but how do you code some limits to the query? a quick look at the snapshot in term meta could give you a date range to limit your query; in the delicate balancing acts of optimization, that might be really helpful
  • as a reporting aid, external tools/services (or another plugin) could be given a way to peek into term meta to track activity over time

I concocted this sample from work developed for a client that had very active newsrooms publishing content on a WP multisite. Their editorial teams made heavy use of the core "Category" taxonomy to organize content and the revenue team was always eager to boost recirculation (and ad $$$). Our work included a suite of article curation tools to support these recirculation strategies.

Central to producing the output was a controller class that executed the curation queries. The idea here is that it could benefit from the extra metadata by being able to add reliable date limits--a handy WP database optimization. For this to work, it's important to measure that the boost to the controller queries outweighs the extra load in computing the maps when articles are published. An important contextual note: we arrived at this solution at the behest of the platform engineers who were, at the time, urging us to remove or otherwise minimize the amount of term queries. Though not included here, those maps also contained post IDs alongside counts. This allowed for fallback strategies that minimized, as requested, expensive term queries, replacing them with simpler post queries with either a data range or explicit list of post IDs (both more efficient alternatives).

About

Involved example of WP backend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages