I have posts sorted by two categories (chapter and paragraph). The paragraph post can contain several tags. Not custom post types.
The chapter has a relation (via ACF) to the paragraph.
I’m want to build a query where I can surface both chapters and paragraphs based on a single tag. For example:
Chapter: 1 Paragraph 1 - Tags (happy, joyful) Paragraph 4 - Tags (sad) Paragraph 8 - Tags (hungry) Chapter: 2 Paragraph 2 - Tags (happy, joyful) Paragraph 3 - Tags (sad) Paragraph 5 - Tags (hungry) Query - Tags = 'sad' Returns Chapter 1, Chapter 2, Paragraph 4, Paragraph 5
I have tested a very inefficient solution where I loop through each post, loop through each relation checking for the right tag. Then storing that post aside including the parent, making sure to not store duplicates. It returns things correctly, but adhorently slow.
I believe that the right path is to start with the tagged posts and then go upstream. The standard wp query parameters don’t seem to provide a clear way to accomplish this. Maybe a straight sql query instead?