I am not familiar with the wordpress schema at all and I need to get back a list, or array of the most recent tags from any post in the wordpress database.
I just need the data available on the home page so I can then manipulate it.
All the functions seem to be designed to work on a per-post basis.
(WordPress really makes me feel sorry for frequent wordpress programmers.)
This ain’t pretty, maybe a MySQL junkie can optimize it a little;
This basically joins the term, term taxonomy, term relationship and post tables together, getting terms that are of the taxonomy ‘post_tag’, and currently have a relation with a post, then ordering them by the post’s date, descending.
You might get the same term in the result set multiple times, but I can’t work out how to use
GROUP BY
orHAVING
to fix this, without messing up the date order.So an example might in use might be;
This is what I wrote as a workaround – sure it’s possible to make it sharper! – to build a tag sitemap (XML, needing
<LOC&>
and<LASTMOD>
…) based on the date of association tag<->post. You could add, at the end of the query, aLIMIT 0,10
to view only the 10 last associated tags.This query will return three columns (name, slug and date of LAST association of single tag) you might use in many ways.
Remember that
wp_
is the default dB prefix in WordPress. You have to change every occurrence with$wpdb->
(see TheDeadMedic’s answer) and be sure to set$wpdb
before the query.