A client’s website has an “Events” blog channel, with a custom module embedded on the template that provides the client with separate fields for the event location, time, registration link, etc.
On the blog listing page, we’ve updated the blog listing module to display those fields and it works perfectly.
However, when we paste that code into a related posts module that lives at the bottom of the blog post template, it only pulls the event data from the event post you’re on, not for each related event.
So if you’re on the page for Event 1, the custom field data for Events 2, 3 & 4 in the related post module will only show the data for Event 1. I’ve pasted the code below. Any help is appreciated.
Figured it out. For reference, we’re using a child theme of Growth, and we’ve copied the Recent Posts module to the child theme. In the blog listing module, they used {% for content … %} and the Recent Posts module used {% for post … %} which is why the same code wasn’t working.
Changed to this:
{% if post.widgets.module_16619998651649.body.event_date_time %}
<strong>Date:</strong>
{{ datetimeformat(post.widgets.module_16619998651649.body.event_date_time,‘%B %e, %Y’) }}
If you’re having trouble pulling custom blog post fields within a recent posts module on a blog post template, here are a few steps to troubleshoot:
1. **Check Field Registration**: Ensure that the custom fields are properly registered in your blog post model.
2. **Update Template Code**: Verify that your template code correctly references the custom fields. For example:
```php
<?php echo get_post_meta($post->ID, ‘custom_field_key’, true); ?>
```
3. **Modify Query**: Make sure your query includes the custom fields. You might need to adjust your `WP_Query` or equivalent to fetch these fields.
4. **Debugging**: Use debugging tools or simple `var_dump` statements to check if the custom fields are being retrieved correctly.
5. **Plugin Conflicts**: Disable other plugins to see if there are conflicts affecting the custom fields.
Would you like more detailed guidance on any of these steps?