A user replied to my question. The answer didn't completely answer my question, but I think it was going down the right path.

Before I could fully test and research further, the answer was deleted.

Is there any way to find this deleted answer?

Here is the question - How to Write a SQL Query to Display list of most used tags in the last 30 days in Wordpress website

  • Not unless you have 10,000 reputation. Or maybe if the owner of that post happens to run across this meta question.
    – animuson StaffMod
    Apr 23 '12 at 2:49
  • 1
    Before anyone asks, the answerer had deleted their own answer. Travis, this discussion may be useful to you. Apr 23 '12 at 3:45
  • @Travis: you told them that their answer did not work, so they deleted it. Sounds like the system works.
    – user7116
    Apr 23 '12 at 13:16
  • 1
    @sixlettervariables true, but most of the answers I get across the SE family of sites are answers that do not work. However, most of the time, these incorrect or incomplete answers help me come up with the correct answer on my own. Apr 23 '12 at 15:18
  • @TravisPflanz: that potentially means your questions do not have enough information for answerers to arrive at the correct answer.
    – user7116
    Apr 23 '12 at 15:21
  • @sixlettervariables or I am asking complete questions and they are so good that nobody has tried them and don't know how to complete them. Go read the question in reference and you tell me it is not complete. Apr 23 '12 at 15:22
  • @TravisPflanz: I have read your question, and without access to your database it is often tough to tell why a given query returns the rows it does.
    – user7116
    Apr 23 '12 at 15:25

This is the original answer, resurrected. Posted here rather then in the original question because I don't want it to get upvotes I don't deserve!

The PHP variables you are inserting in your SQL string are the PHP objects that can be used to access WordPress tables from within PHP; whereas you are after the names of the tables and columns for accessing the data from within SQL.

You want instead:

"SELECT DISTINCT term_taxonomy_id FROM wp_term_relationships
  INNER JOIN wp_posts ON wp_posts.ID = wp_term_relationships.object_id
  WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= wp_posts.post_date"

As an aside: should you ever need to insert the value of a PHP variable into a SQL statement, be very careful to escape it first in order to prevent any malicious code from being injected.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .