Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1421082

    nakeviadesigns
    Participant

    Hi,

    I cannot figure out how to get the custom fields to show within the post area, without breaking the theme. Can anyone assist me? Preferably under the post meta. I am assuming that I am adding them to the wrong file, but this what the only file I felt comfortable touching lol.

    I duplicated the single.php and called it single-adoptable. /wp-content/themes/x-child

    <?php
    
    // =============================================================================
    // VIEWS/INTEGRITY/WP-SINGLE.PHP
    // -----------------------------------------------------------------------------
    // Single post output for Integrity.
    // =============================================================================
    
    $fullwidth = get_post_meta( get_the_ID(), '_x_post_layout', true );
    
    ?>
    
    <?php get_header(); ?>
    
      <div class="x-container max width offset">
        <div class="<?php x_main_content_class(); ?>" role="main">
    
          <?php while ( have_posts() ) : the_post(); ?>
            <?php x_get_view( 'integrity', 'content', get_post_format() ); ?>
            <p><strong>Breed: </strong><?php the_field('breed'); ?><br>
            <strong>Age: </strong><?php the_field('age'); ?><br>
            <strong>Size: </strong><?php the_field('size'); ?><br>
            <strong>Expected Size: </strong><?php the_field('expected_size'); ?><br>
            <strong>Good with Kids? </strong><?php the_field('good_with_kids'); ?><br>
            <strong>Good with Other Dogs? </strong><?php the_field('good_with_other_dogs'); ?><br>
            <strong>Good with Cats? </strong><?php the_field('good_with_cats'); ?></p>
            <?php x_get_view( 'global', '_comments-template' ); ?>
          <?php endwhile; ?>
    
        </div>
    
        <?php if ( $fullwidth != 'on' ) : ?>
          <?php get_sidebar(); ?>
        <?php endif; ?>
    
      </div>
    
    <?php get_footer(); ?>
    
    #1421092

    nakeviadesigns
    Participant
    This reply has been marked as private.
    #1421241

    Rad
    Moderator

    Hi there,

    Instead of using the custom template, you could use a the_content filter. Example, please add this code to your child theme’s functions.php

    add_filter('the_content', 'display_custom_fields_value', -99999);
    
    function display_custom_fields_value ( $content ) {
    
    if ( is_singular('post') ) :
    
    ob_start(); ?>
    
            <p><strong>Breed: </strong><?php the_field('breed'); ?><br>
            <strong>Age: </strong><?php the_field('age'); ?><br>
            <strong>Size: </strong><?php the_field('size'); ?><br>
            <strong>Expected Size: </strong><?php the_field('expected_size'); ?><br>
            <strong>Good with Kids? </strong><?php the_field('good_with_kids'); ?><br>
            <strong>Good with Other Dogs? </strong><?php the_field('good_with_other_dogs'); ?><br>
            <strong>Good with Cats? </strong><?php the_field('good_with_cats'); ?></p>
    
    <?php $content .= ob_get_clean();
    
    endif;
    
    return $content;
    
    }

    The -99999 is to make sure it’s displayed before the content, and of course under the meta 🙂

    Thanks!

    #1423001

    nakeviadesigns
    Participant

    Hi,

    Thank you so much! I have regular blog posts and I have a custom post type (Adoptables), which I am inserting these fields into. Would I change ‘post’ in the if statement to ‘adoptable’?

    I tried it. It worked! You Guys are awesome!!! However, it shows under the content…Either way, it worked!

    #1423431

    Jade
    Moderator

    Hi there,

    Yes, you may change post to adoptable if it is the custom post type you’re working on.

    Thank you.

    #1425213

    nakeviadesigns
    Participant

    The -99999 didn’t send it above the post body…any thoughts on that?

    #1425294

    Paul R
    Moderator

    Hi,

    To make it appear above your post.

    Please change the code to this.

    
    add_filter('the_content', 'display_custom_fields_value', -99999);
    
    function display_custom_fields_value ( $content ) {
    
    if ( is_singular('post') ) :
    
    ob_start(); ?>
    
            <p><strong>Breed: </strong><?php the_field('breed'); ?><br>
            <strong>Age: </strong><?php the_field('age'); ?><br>
            <strong>Size: </strong><?php the_field('size'); ?><br>
            <strong>Expected Size: </strong><?php the_field('expected_size'); ?><br>
            <strong>Good with Kids? </strong><?php the_field('good_with_kids'); ?><br>
            <strong>Good with Other Dogs? </strong><?php the_field('good_with_other_dogs'); ?><br>
            <strong>Good with Cats? </strong><?php the_field('good_with_cats'); ?></p>
    
    <?php $output .= ob_get_clean();
    $content = $output.$content;
    endif;
    
    return $content;
    
    }
    

    Hope that helps.