Support » Plugin: Content Blocks (Custom Post Widget) » Custom fields

  • Resolved magicspon



    I am using this plugin with the Advanced Custom Fields (acf v.4) plugin. I’ve been able to add custom fields to my content blocks. Now I just need to get them to display in my widget.

    I have asked for some assistance on the ACF forum, the develop has come back to me and asked if I have the post_id variable for the content block


    At the moment I have had to pass in the post ID in order for the custom field to display in my theme. (Using the Warp theme framework from yootheme).

    Here is the code:

    <div class="module <?php echo $style; ?> deepest">
    <?php echo $badge; ?>
    <?php if ($showtitle) echo $title; ?>
    <?php echo $content; ?>
    <?php the_field('panel_link',803); ?>

    <?php the_field(‘panel_link’,803); ?> is my custom field, and 803 is the ID of the post.

    Obviously for this to work I can’t hardcode in the ID of the post.

    I can see a previous post has asked a similar question but it is marked as resolved so I am unable to comment on it.

    Any help, greatly appreciated


Viewing 7 replies - 1 through 7 (of 7 total)
  • Sorted

    in my widget code i’ve added in the following line:

    Which gets the custom field and the ID of the content block
    <?php the_field('panel_link',$customPostId); ?>

    I’ve set $customPostId) in the module.php file in the warp framework

    $customPostId = (!empty($module->params['custom_post_id']))? $module->params['custom_post_id'] : null;


    I’m having the same issue but I’m not sure how to go about this.

    My Content Blocks have 2 custom fields. So how do I display them on my site? Currently it only shows the title and the content, and I want to add the values of the custom fields.

    Are you using the Warp framework from yootheme?

    If you are.. this is the code for one of my custom blocks

    <div class="module <?php echo $style; ?> deepest">
    	<?php echo $badge; ?>
    	<div class="title">
    		<i class="icons icons-icon_bulb_big"></i>
    		<?php echo get_field('cb_heading',$customPostId); ?>
    	<div class="message">
    		<?php echo $content;?>

    Nope, I’m not…. I just wanted to place the custom fields in the widget code (regardless of the theme), and I managed to do that.

    So let’s say I have a custom field (using Advanced Custom Fields) called “event_description” that is added to my Content Blocks.

    In \wp-content\plugins\custom-post-widget\post-widget.php, in the function “widget” (starting at line 82), I added the following lines in the part where the widget is being written:

    $evt_desc = get_field('event_description',$custom_post_id);
    if ($evt_desc) {echo $evt_desc;}

    The result is that the value of that custom field is then being displayed in the widget on the front end.

    It’s very simple! 🙂

    sorry, I don’t really know WordPress and my php is lacking.. can’t really help you I’m afraid. Have you looked on

    good luck

    Hmmmm no, I don’t need help anymore, in my previous post I wrote the solution. 🙂

    hhaha.. sorry! too many beers and dev! ;}

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom fields’ is closed to new replies.