content_by_id not pulling through blog content when a id is used.
SOLVE
I am hoping someone can help me with content_by_id not pulling through blog content when an id is used.
I have made a custom module (code below) it loops through pages selected by the marketing team using the page field. For each item in the loop, I use content_by_id to grab the title, featured image and description about the blog.
This sometimes works and sometimes doesn't - item.blog_pages always gets the id but doesn't get the rest of the content.screen shot of what is seen
{% set blogs = content_by_id(item.blog_pages) %} {{item.blog_pages}} -- shows item id fine {% if blogs.featured_image %} <div class="three-page-select-img-wrapper"> <img src="{{ blogs.featured_image }}" loading="lazy" class="three-page-select-img" alt="{{ blogs.featured_image_alt_text | escape }}"> </div>
content_by_id not pulling through blog content when a id is used.
SOLVE
There is a funtion that accepts an array of page ids content_by_ids that I would suggets exploring.
I was looking for a resource to demonstrate how to fill an array and I was pleasantly surprised to see that @alyssamwilie has something on her site (and I didn't even know she had a site 😯) that might help. It is pretty clever!
Did I test it? No. 🙃 If you try it, let us know how it works out.
Note that the limit is the amount of calls you can make is 10 and not the amount of posts. For the content_by_ids, you can fit 100 posts into an array so in theory, you could have up to 1000posts.
content_by_id not pulling through blog content when a id is used.
SOLVE
@jonchim Hi thanks for sending me that, it does seem to be that it only doesn't work after the 10th one. Any suggestions on what I could do instead - I would add pagination but I don't want multiple pages.
It looks like this function has a limit of 10 calls per page, which may explain why you can't see anything be pulled after the 10th blog post on your listing page.
Can you confirm and test that by making the blog that wasn't displaying and make that the 10th post and see if it shows up?
No problem! yeah that is very odd, thank you for sharing the video context. If you're able to package the module I can take a closer look. I tried using the module code but the missing css/js/module fields may help me troubleshoot further.
content_by_id not pulling through blog content when a id is used.
SOLVE
Hi @jonchim thanks for having a look, that weird div you found it just link text which I've added default text now, no all the sections do not need to be filled out to work. However, I have seen some odd behaviour - When I edit a field in the editor the page refreshes and gets all the content and when I save it disappears again - I've added a video https://drive.google.com/file/d/1I_3prbVWp1GqHvASRnkEI7k4Dt4Kezw4/view?usp=sharing showing this here - Would you like me to zip up the module code for you and send it to you?
content_by_id not pulling through blog content when a id is used.
SOLVE
Hey @MGilbert, it's hard to pinpoint where exactly the code is breaking but I noticed that the blogs that break don't have links compared to the blogs towards the top? Are they all using the same module? And do all the fields need to be filled out in order to display properly? I can see a weird div inside of a link not sure if that's causing it to break. Since i'm not a user on your portal i'm unable to view the custom module, but happy to take this offline to take a closer look.