Hi Guys, are there any known reasons why ACF values would not render within pages created using VC, I have registered a custom module that has two buttons, these two buttons only show if a value is set in ACF additional field, they work fine in category view but not within a page generated with VC. A custom block has also been registered which uses the same module, it renders fine except the two buttons which should be visible, are not.
Image outlining issue;

Thanks
Matt
Hello Matt,
Since this is a custom implementation it is hard to say why this happens. We did not test implementing ACF in our theme blocks or modules. You will need to inspect the block code and see if there is any part that could affect your modification.
Thanks.
Hi Bogdan, I’ve tried various things but it definitely seems like once the module is registered as a block in td_config.php and used on a page inside visual composer it loses the ability to properly select the post meta ACF field values.
I use ACF inside single post templates and all works fine, I used ACF in category view with a custom registered module and all works fine, it’s just when the same module is registered as a VC Block, all ACF values are lost.
Any ideas?
Matt
I understand the problem. You can run ACF on a module, but not on a block. Yes. But blocks are made out of 1 or more modules. They are entirely different elements altogether.
The blocks are found here: https://www.screencast.com/t/2w0Ytfvp but I cannot offer any solution in this regard as the plugin is not tested to work with our modules or blocks. I recommend hiring a freelancer to help out with the code needed.
Thank you!
Hi Bogdan, how would we pull the post ID for each item inside a block loop into the module? Would it need to be registered in td_module.php in the same way that these module parts are;
<?php echo $this->get_author();?>
<?php echo $this->get_date();?>
<?php echo $this->get_comments();?>
Because simply adding
<?php echo get_the_ID()?>
Does the exact same thing as we’re outlined, works fine on category archibe page, and displays the main page ID when used in a Visual Composer Block.
Thanks
Matt
Hi,
Maybe you can try it like this if you want to get the post ID, you will have to make the modification for each module
– https://www.screencast.com/t/E6oV2jiRMtQd
Thanks
Hi Simion, this has now helped to resolve the issue, by using ‘<?php $mk_current_post_id = $this->post->ID;?>’ inside the custom module I have defined the ACF fields now work as they should do, without this define variable the loop does not work, it simply uses the parent page ID and not the current post ID within the loop, here’s my full working code;
<?php
$mk_current_post_id = $this->post->ID;
?>
<!– START Publication Links–>
<?php if( get_field(‘mk_acf_pub_pagesuite_link’, $mk_current_post_id) ): ?>
<div class=”mk-module-ebook-links”>
” target=”_blank”>Open In PageSuite
<?php endif; ?>
<?php if( get_field(‘mk_acf_pub_pdf_link’, $mk_current_post_id) ): ?>
” target=”_blank”>Download PDF
</div>
<?php endif; ?>
<!– END Publication Links –>
Thanks
Matt
Hi Guys, it’s been a while since I originally experienced this issue but I just wanted to pick it up again as I’m having similar problems again.
I’ve recently updated to tagDiv Composer 3.9 and I’m using the same method outlined in this thread to display ACF custom fields inside custom shortcodes in composer.
I can see from the td_module.php file in tagDiv composer you use the following to select field values from the current post too.
$post_id = $this->post->ID;
But this also causes a fatal error if I include it in my shortcode template file.
This is what my shortcode looks like.
$post_id = $this->post->ID;
if ( get_field( ‘mk_acf_contributor_primary_role’ , $post_id ) ):
the_field( ‘mk_acf_contributor_primary_role’ , $post_id );
Am I missing anything obvious?
I’ve seen you’ve added ACF support in composer but I need to do compile more complex elements which add links from ACF fields etc too so I need to be able to define my own custom template parts compiled from ACF field data.
Thanks
Matt
Hi Bettina, I’m trying to use ACF fields as part of custom shortcodes used in tagDiv Composer. If the post id isn’t defined the fields don’t return any values, so the shortcodes I’m using need to have some way of setting the queried post id.
This is how I’ve done it previously.
$mk_current_post_id = $this->post->ID;
if ( get_field( ‘mk_acf_contributor_primary_role’ , $mk_current_post_id ) ):
the_field( ‘mk_acf_contributor_primary_role’ , $mk_current_post_id );
This returns a fatal error.
Yes, we’re initially trying to use it in a cloud template for a custom post type.
I’ve tried to use the_title() in the same shortcode template file but this prints ‘Custom Template Name’ instead of the title of the post being displayed.
If we use ACF fields they display nothing.
If we then add the $mk_current_post_id = $this->post->ID; or $post_id = $this->post->ID; to the shortcode template file it creates a fatal error.
Hello Matt!
If you would like to add the shortcode to a single cloud template, then you should write the code like this:
global $tdb_state_single;
$post_id = $tdb_state_single->post_id->__invoke();
This will take the real post id, not the template id as you wrote the code above.
I hope that helps you!
Thank you!
Hi Bettina, thanks for that, it seems to have resolved the issue.
Would we have to use a similar definition for custom taxonomy cloud templates to check the queried term_id?
Matt
