• Resolved sproutchris

    (@sproutchris)


    I’m trying a run a database query to see what the total amounts of authors set to an article is in our WordPress setup. I don’t see anything being saved in the post meta table so I’m not sure where I can grab this information. I need a MySQL query that gets all the posts along with the number of total authors set to each of those posts. Can anyone help me out with this? I would really appreciate it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Sproutchris,

    May be this is goanna help. You have to may have to write different queries to get all the authors for the article.

    For Co-authors

    1. Firstly all the authors are saved in the term_taxonomy table (“term_taxonomy“)
    2. Where they are assigned different term_id. For eg: Term_id is 1 for author A.
    3. In the terms table (“terms), you can see that for term_id 1, author details will be there.
    4. And Finally in the ?term_relationships table, the postID, their co_author and the order in which they are saved are present. PostID is the object ID, co_author is the termID and the last coulumn will contain the order.

    So you have to take the post ID and get the termIds from the term_relationships table. Once you get the termIds, you can get the co-authors ID for the particular post.

    Thread Starter sproutchris

    (@sproutchris)

    I believe this works:

    SELECT ID as post_id, COUNT(ID) AS total_authors FROM wp_posts
    JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id
    JOIN wp_terms on wp_term_relationships.term_taxonomy_id = wp_terms.term_id
    WHERE post_status='publish' AND wp_terms.slug LIKE 'cap-%'
    GROUP BY post_id

    To narrow down the posts with multiple authors, you can add HAVING total_authors > 1 at the end of the query.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘finding the amount of authors in each post via database query’ is closed to new replies.