1

I've managed to add a custom post type that contains custom fields using Toolset's wp-types plugin. I've also figured out by trial & error how to create & edit a single-goal.php file to show my custom fields... all good so far.

My problem is that I can't work out how to shortcode my new post type (goal) to show up on a page in my theme (I'm using Flexform). Something to do with the theme not recognizing the new post type maybe???? (as I said I'm way out of my depth here).

As a work around I've edited my single.php which allows me to use all the shortcode placement functionality that the theme offers and put the 'posts' wherever I want. The problem of course is that my new fields (labels, etc) will now show on all posts.

Could some kind code warrior help me to tweak my code below so that the fields and other elements will only show if a field has a value.

I also suspect that there is a much better way to achieve what I'm written below. Please feel free to offer any suggestions.

p.s. I know that I could use the echo function to call up a label, but that is problematic as the goal & commitment values have multiple-instances and it creates multiple labels.

<section class="article-body-wrap">
<div class="body-text clearfix">
    <?php the_content(); ?>

    <span class="heading-wrap"><h6 class="wpb_heading wpb_text_heading"><?php _e("My Goals: "); ?></h6><span><?php echo types_render_field("goal", array("user_current"=>"true")); ?></span></span>
    <?php echo "<br>"; ?>
    <?php echo "<hr>"; ?>

    <span class="heading-wrap"><h6 class="wpb_heading wpb_text_heading"><?php _e("My Commitments: "); ?></h6><span><?php echo types_render_field("commitment", array("user_current"=>"true")); ?></span></span>
    <?php echo "<br>"; ?>
    <?php echo "<hr>"; ?>

    <span class="heading-wrap"><h6 class="wpb_heading wpb_text_heading"><?php _e("Strengths to leverage: "); ?></h6><span><?php echo types_render_field("strengths-to-leverage", array("user_current"=>"true")); ?></span></span>
    <?php echo "<br>"; ?>
    <?php echo "<hr>"; ?>

    <span class="heading-wrap"><h6 class="wpb_heading wpb_text_heading"><?php _e("Barriers to success: "); ?></h6><span><?php echo types_render_field("barriers-to-success", array("user_current"=>"true")); ?></span></span>
    <?php echo "<br>"; ?>
    <?php echo "<hr>"; ?>

    <span class="heading-wrap"><h6 class="wpb_heading wpb_text_heading"><?php _e("What will success look like?: "); ?></h6><span><?php echo types_render_field("what-will-success-look-like", array("user_current"=>"true")); ?></span></span>
    <?php echo "<br>"; ?>
    <?php echo "<hr>"; ?>

    <span class="heading-wrap"><h6 class="wpb_heading wpb_text_heading"><?php _e("How will I Monitor and Measure?: "); ?></h6><span><?php echo types_render_field("how-will-i-monitor-and-measure", array("user_current"=>"true")); ?></span></span>
    <?php echo "<br>"; ?>
    <?php echo "<hr>"; ?>


</div>
0

I believe you might be looking for this:

Types Conditional FIelds Display

And set each field to display only if not empty.

Then you can set up an array of field labels...

$fields['goal'] = 'My Goals: ';
$fields['commitment'] = 'My Commitments :';
// ... and so on...

Then loop through the fields to display them:

foreach ($fields as $fieldkey => $fieldlabel) {
    $field = types_render_field($fieldkey,array("user_current"=>"true");
    if ($field) {
        echo '<span class="heading-wrap"><h6 class="wpb_heading wpb_text_heading">';
        echo $fieldlabel.'</h6><span>'.$field.'</span></span>';
        echo '<br><hr>';
    }
 }

This assumes types_render_field returns false if the field is empty... you may have to test that to find out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.