Tagged: x
-
AuthorPosts
-
March 26, 2017 at 8:58 pm #1421082
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(); ?>
March 26, 2017 at 9:01 pm #1421092This reply has been marked as private.March 27, 2017 at 1:23 am #1421241Hi 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!
March 28, 2017 at 8:34 am #1423001Hi,
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!
March 28, 2017 at 3:29 pm #1423431Hi there,
Yes, you may change post to adoptable if it is the custom post type you’re working on.
Thank you.
March 30, 2017 at 6:09 am #1425213The -99999 didn’t send it above the post body…any thoughts on that?
March 30, 2017 at 8:46 am #1425294Hi,
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.
-
AuthorPosts