custom fields not working for blocks

Posted in: Newsmag
Post count: 7

Hi,

another question:

I need to use custom fields for my posts. I am therefore using the ACF plugin and using the code to display the custom field ( the_field (“name_of_the_field”) ) works perfectly well for the modules. However I would like to show the custom fields on the blocks as well. According to the documentation eg block layout 7 is made from module layout 6. The field is shown on module 6 but not on block 7 => so I assume I need to enter the code for displaying the custom field somewhere else. Can you help pls. and as I am not familiar with php pls. guide me through.

Many thanks!
Christoph

Post count: 6600

Hi,

Not sure how you added it. Having it shown on module 6 then it should also appear on block 7. Please provide more details about how you’dd add it and also provide your site’s url with an example.

Thanks

Post count: 7

Hi Lucian,

here is the modified code of td_module_6.php with 2 custom fields and 2 CSS selectors

<?php

class td_module_6 extends td_module {

function __construct($post) {
//run the parrent constructor
parent::__construct($post);
}

function render() {
ob_start();
?>

<div class="<?php echo $this->get_module_classes();?>" <?php echo $this->get_item_scope();?>>

<?php echo $this->get_image('td_100x75');?>

<div class="item-details">

<span id="datfei"><?php the_field('datum_feiertag'); ?></span><br/><span id="gueltigkeit"><?php the_field('gueltigkeit'); ?></span>
<?php echo $this->get_title();?>
<?php if (!empty($td_mod_single->td_post_theme_settings['td_subtitle'])) { ?>
<p class="td-post-sub-title"><?php echo $td_mod_single->td_post_theme_settings['td_subtitle'];?></p>
<?php } ?>
<div class="meta-info">
<?php if (td_util::get_option('tds_category_module_6') == 'yes') { echo $this->get_category(); }?>
<?php echo $this->get_author();?>
<?php echo $this->get_date();?>

<?php //echo $this->get_comments();?>
</div>
</div>
<?php echo $this->get_item_scope_meta();?>
</div>

<?php return ob_get_clean();
}
}

here are 2 links:

this is a category page using the module 6 (working fine):

Module 6 page

this is a page using the block 7 in the sidebar (it would also not work if I add a VC block 7 in the content – already tried that) – you see that the CSS is there (black background) but no content…

block 7 page

regards
Christoph

Post count: 9544

You might try this

<?php echo $this->the_field('datum_feiertag'); ?>

I think there needs to be something there to say “get from this record” … vs just echoing the field unless the field applies to everything on the site.

That could be wrong… just a thought ….

I use ACF on one of my sites .. love it 🙂

Post count: 7

Hi Chris,

thought of that as well – many thanks! Unfortunately does not work but surprisingly breaks the module display…


@Lucian
: can you help

thanks
christoph

Post count: 9544

(ha… thought that might be too easy!)

Post count: 7

hope it would be that easy 🙂

Post count: 7

Update:
block does not work with WP native custom fields either
code – eg:
<?php $gueltig = get_post_meta( get_the_ID(), 'gueltig', true);
echo $gueltig; ?>
works perfectly well for single post templates & module templates but is not passed onto block.

Post count: 6600

Hi,

Sorry for the delay!
Blocks uses different loop from the one used on modules/categories.
Try it like this: post->ID , 'gueltig', true);
echo $gueltig; ?>

Thanks

Post count: 7

Hi Lucian,

many thanks – works!

Just a minor one for non-coders like me:
should start with..
<?php $gueltig

Again, Thanks – great support
Christoph

Viewing 10 posts - 1 through 10 (of 10 total)
The forum ‘Newsmag’ is closed to new topics and replies.