Creating WP Query String to Loop Products from a Page Title

I’m still researching an answer on this one but the situation is that I have several info pages made that list products related to the page name. Those page names are in a taxonomy that’s part of the products metadata so it’s all interconnected.

I figure I could pull the products I need by using the page title like so:

post_type=product&tax_query%5Btaxonomy%5D=product_cat&tax_query%5Bterms%5D=c

However, all this does is pull the latest products in order which means the last part isn’t being read.

Another idea is to set up a looper for all products with Meta Values set to filter out every product that doesn’t have an entry for that particular taxonomy. After that, I figure I could make another looper using a query string to just target the filtered results with the value of the page title but that doesn’t seem to work either.

image

In this case, there’s a custom taxonomy called “Artist” which I’m able to use as the Meta Key to filter out the products I need. However, I guess I don’t know what values I’m able to put in to Meta Value to make the page template dynamic. I tried putting in a sub-taxonomy ID, the sub-taxonomy term itself and of course the page title {{dc:post:title}} as well. I imagine I’m probably using Meta Values wrong here but I will keep spelunking for answers.

Hello @dobacco,

Thanks for writing in!

You can use “Artist NOT LIKE {{dc:post:title}}” .

Hope this helps.

Rue, thanks for the assist as always. I don’t know why I didn’t try this before!

So I actually needed the opposite result so what I ended up doing was keeping the above rule artist != and then made a second rule artist LIKE "artist ID value" and it appears to work but now I realize that maybe I need to try something different as obviously the value of {{dc:post:title}} will not be the same ID value as the equivalently named taxonomy entry in Artists.

I’ll take a guess that I should choose “Dynamic Content” instead and write code that grabs {{dc:post:title}} and then checks that against the entries in the Artists taxonomies which will then allow me to get the correct ID value.

In the end, I gave up and decided there was no reason to do this on a Wordpress Page and just moved all the info I was trying to display to the top of the Product Categories template where it would be easy to find and one less click.

Hello @dobacco,

As long as there is a relation of the post type to the title, then you can make a query out of it. But then, it is best not to complicate things because it will be easier to troubleshoot if some issues comes along.

Cheers.