Greetings all,
I’m using a query to list only the set of entries in a weblog that have a custom drop-down field set to “yes.” This works just great, but I also need to display the title of a related entry. Inside of a query, however, I can only get an ID# of the related entry (which also doesn’t appear to be the same as the entry ID).
Trying to nest queries gives me errors, and I can’t do a weblog entries tag inside the query either. I am wondering if I need to use PHP to pull the related info in, or would ‘joining’ tables in some way be recommended for getting info about related entries inside of a query?
To make it more concrete, I’m setting up a complex discography, in which a weblog called “tracks” lists remixes and versions of “songs” in a “songs” weblog. Thus, each “track” is like an instance of a “song.” Here’s the query that produces a list of tracks with a drop-down field (its ‘downloadable’ setting) set to ‘yes.’
{exp:query sql="SELECT t.entry_id, title, field_id_34 as songid, field_id_37 as tracklength, url_title FROM exp_weblog_titles AS t, exp_weblog_data AS d WHERE t.weblog_id=7 AND t.entry_id = d.entry_id AND field_id_70 ='yes' ORDER BY title"}
{title} | {tracklength} | {songid}
{/exp:query}The title of the related entry (the song entry’s title) is what I’m looking to display in here, rather than songid. Field_id_34 is the field in the “tracks” weblog where the title of the “related song” (that the track is a remix of) is chosen.
I’m just hoping to be steered in the right direction toward the “recommended way of doing this…,” not having the work done for me or anything like that! I’m just wrapping my head around ‘joining’ tables now, but trying to figure out how to do in the context of ‘related entries’ is a challenge. It would be hugely helpful if someone could just recommend doing this either with PHP or a join in a query tag. Thanks so much!
R o B