Re: Link product & blog posts by blog post metafield

Link product & blog posts by blog post metafield

spicemerchant
Tourist
7 0 1

Hello, each of our 500+ blog posts has a metafield for related products. The metafield type is a Product List.

 

I want to use this blog post metafield data to be able to show the blog posts on the page for their related products.

 

Is there a way to do this? 

  1. Loop through all blog articles and check the metafield?
  2. Query blog posts somehow in a Liquid template?
  3. Create own app?
Replies 8 (8)

Dirk
Shopify Staff
2396 256 527

Hey, @spicemerchant 

 

This does sound like custom app territory as I haven't come across an existing app that does this. I'm confident one of our Shopify experts would be able to accomplish this at a reasonable price.
 
Just wanted to share this as an option in case you are unable to find a coding solution in your thread.

 

If there is anything else I can help you with, please let me know.

Dirk | Social Care @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

spicemerchant
Tourist
7 0 1

Thanks for the fast reply, Dirk!

 

Is there a GraphQL query to get blog posts by product in a metafield? If so I might be able to do this with Mechanic.

 

Or with my own app... I'm a rails and js developer as well. Just need a good starting point.

MaxDesign
Shopify Partner
213 15 84

So, what you want to do is suggest related blog articles in product pages right?

There is a way to loop over all blog articles in your product page, and then for each blog article loop over the product list metafields to see if there is a match. The main issue with this approach is that it is a nested loop startegy, knowing that you have 500+ articles... There is a trick to achieve this using pagination (not tried for awhile but I think this can work) ; but to be frank, this is taking the problem from the wrong end, and is not a great idea for performance.

Since what you need to modify is the product page, could you not add a metafield in your product page instead of blog page? This metafield would be a list of related blog articles for your product. 

Shopify is known for doing some things halfway, and I have no idea why there is not a blog or article reference available in metafields. So until this becomes a thing, you could still create a metafields of type "single line texte" with "list of values" option. And for each product, you would add the articles "handle" that you want. 

You can access a blog article in product page by its handle like this (here I'm assuming there is only one blog):

{%- assign article = articles['blog-handle/article-handle'] -%} 
{{ article.title }}

Of course this code snippet would need to be adjusted  to retrieve the article handles from the product metafield, but you get the idea.

Reach out to me at admin@maxdesign.expert
spicemerchant
Tourist
7 0 1

Thanks Max. I've considered that, but we don't want the work flow of updating multiple products' metafields every time we have a new blog post. The management will be unwieldy.

 

I think we'll need to make a custom app. The data already exists in Shopify so it's a matter of getting it out.

MaxDesign
Shopify Partner
213 15 84

You will still need to figure out how you render the blog post articles in your product pages. If you want the blog articles to be rendered server-side, using product metafields seems like a good approach (as I explained above).

I guess your app could be watching for when new articles are created, and create/migrate metafields data to the product metafield. By the way this can be done in a quick fashion using a "no-code" tool such as Make (Shopify Flow does not support yet watching for new articles).

Reach out to me at admin@maxdesign.expert
spicemerchant
Tourist
7 0 1

I might try that! Right now, if I could get the Rails private app working... this app itself will be really straightforward.  🙂

Aurnik
Shopify Partner
51 1 4

Just curious, what kind of related blog posts are you showing on the product pages? Is that a way of driving traffic to the blog posts, or are they specifically relevant to those products? Sounds pretty cool.

Product Embed - embed products into blog posts - shopify.com/product-embed
Blog Sync - copy new & updated blog posts across stores - shopify.com/blog-sync
spicemerchant
Tourist
7 0 1

We have recipes featuring food products, so want the product pages to link to the specific recipes that use them, without creating extra work to go link/unlink outside of setting the product list metafield on the recipe. Thanks!