Support

Account

Home Forums Front-end Issues Can't display data on post

Solved

Can't display data on post

  • Disclaimer–A programmer I am not. I’m sure there is a simple solution, but I can’t wrap my mind around it.

    ACF is working great on the backend of the site I’m working on. I can’t get it to display anything on the front end.

    I have 30 posts entered of the custom post type “gg_trailers”. A listing of the posts shows up with the featured image, but none of the details that I’ve entered into ACF.

    How do I get the ACF information to show up on the posts when they’re displayed? The ACF PHP export is below for reference.

    if(function_exists("register_field_group"))
    {
    	register_field_group(array (
    		'id' => 'acf_basic-trailer-information',
    		'title' => 'Basic Trailer Information',
    		'fields' => array (
    			array (
    				'key' => 'field_539704364ecd7',
    				'label' => 'Type',
    				'name' => 'type',
    				'type' => 'text',
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    			array (
    				'key' => 'field_539612dc77795',
    				'label' => 'Year',
    				'name' => 'year',
    				'type' => 'number',
    				'instructions' => 'Use a 4 digit year.',
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '',
    				'append' => '',
    				'min' => '',
    				'max' => '',
    				'step' => 0,
    			),
    			array (
    				'key' => 'field_5396132e77797',
    				'label' => 'Model',
    				'name' => 'model',
    				'type' => 'text',
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    			array (
    				'key' => 'field_539613afbb001',
    				'label' => 'Price',
    				'name' => 'price',
    				'type' => 'text',
    				'instructions' => 'Do not include a dollar sign ($), just the amount.',
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '$',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    			array (
    				'key' => 'field_5398a0e15aab9',
    				'label' => 'Sales Price',
    				'name' => 'salesprice',
    				'type' => 'text',
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '$',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    			array (
    				'key' => 'field_5396130877796',
    				'label' => 'MFG',
    				'name' => 'mfg',
    				'type' => 'text',
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    			array (
    				'key' => 'field_5396133777798',
    				'label' => 'Size',
    				'name' => 'size',
    				'type' => 'text',
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    			array (
    				'key' => 'field_5396133c77799',
    				'label' => 'Stock #',
    				'name' => 'serial',
    				'type' => 'text',
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    			array (
    				'key' => 'field_5396134d7779a',
    				'label' => 'VIN #',
    				'name' => 'vin',
    				'type' => 'text',
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    			array (
    				'key' => 'field_5396135a7779b',
    				'label' => 'Specs',
    				'name' => 'specs',
    				'type' => 'file',
    				'instructions' => 'Attach Spec Sheet PDF HERE.',
    				'save_format' => 'object',
    				'library' => 'all',
    			),
    		),
    		'location' => array (
    			array (
    				array (
    					'param' => 'post_type',
    					'operator' => '==',
    					'value' => 'gg_trailers',
    					'order_no' => 0,
    					'group_no' => 0,
    				),
    			),
    		),
    		'options' => array (
    			'position' => 'normal',
    			'layout' => 'no_box',
    			'hide_on_screen' => array (
    				0 => 'custom_fields',
    			),
    		),
    		'menu_order' => 0,
    	));
    	register_field_group(array (
    		'id' => 'acf_image-gallery',
    		'title' => 'Image Gallery',
    		'fields' => array (
    			array (
    				'key' => 'field_53b1a6934e200',
    				'label' => 'Image 1',
    				'name' => 'image_1',
    				'type' => 'image',
    				'save_format' => 'object',
    				'preview_size' => 'thumbnail',
    				'library' => 'all',
    			),
    			array (
    				'key' => 'field_53b1a6d69a981',
    				'label' => 'Image 2',
    				'name' => 'image_2',
    				'type' => 'image',
    				'save_format' => 'object',
    				'preview_size' => 'thumbnail',
    				'library' => 'all',
    			),
    			array (
    				'key' => 'field_53b1a9a4342af',
    				'label' => 'Image 3',
    				'name' => 'image_3',
    				'type' => 'image',
    				'save_format' => 'object',
    				'preview_size' => 'thumbnail',
    				'library' => 'all',
    			),
    			array (
    				'key' => 'field_53b1a9a3342ae',
    				'label' => 'Image 4',
    				'name' => 'image_4',
    				'type' => 'image',
    				'save_format' => 'object',
    				'preview_size' => 'thumbnail',
    				'library' => 'all',
    			),
    			array (
    				'key' => 'field_53b1a9a3342ad',
    				'label' => 'Image 5',
    				'name' => 'image_5',
    				'type' => 'image',
    				'save_format' => 'object',
    				'preview_size' => 'thumbnail',
    				'library' => 'all',
    			),
    			array (
    				'key' => 'field_53b1a9a2342ac',
    				'label' => 'Image 6',
    				'name' => 'image_6',
    				'type' => 'image',
    				'save_format' => 'object',
    				'preview_size' => 'thumbnail',
    				'library' => 'all',
    			),
    			array (
    				'key' => 'field_53b1a9a2342ab',
    				'label' => 'Image 7',
    				'name' => 'image_7',
    				'type' => 'image',
    				'save_format' => 'object',
    				'preview_size' => 'thumbnail',
    				'library' => 'all',
    			),
    			array (
    				'key' => 'field_53b1a9a1342aa',
    				'label' => 'Image 8',
    				'name' => 'image_8',
    				'type' => 'image',
    				'save_format' => 'object',
    				'preview_size' => 'thumbnail',
    				'library' => 'all',
    			),
    			array (
    				'key' => 'field_53b1a9a0342a9',
    				'label' => 'Image 9',
    				'name' => 'image_9',
    				'type' => 'image',
    				'save_format' => 'object',
    				'preview_size' => 'thumbnail',
    				'library' => 'all',
    			),
    			array (
    				'key' => 'field_53b1a99d342a8',
    				'label' => 'Image 10',
    				'name' => 'image_10',
    				'type' => 'image',
    				'save_format' => 'object',
    				'preview_size' => 'thumbnail',
    				'library' => 'all',
    			),
    		),
    		'location' => array (
    			array (
    				array (
    					'param' => 'post_type',
    					'operator' => '==',
    					'value' => 'gg_trailers',
    					'order_no' => 0,
    					'group_no' => 0,
    				),
    			),
    		),
    		'options' => array (
    			'position' => 'side',
    			'layout' => 'default',
    			'hide_on_screen' => array (
    			),
    		),
    		'menu_order' => 0,
    	));
    	register_field_group(array (
    		'id' => 'acf_notes',
    		'title' => 'NOTES',
    		'fields' => array (
    			array (
    				'key' => 'field_53dbf3e3cc08b',
    				'label' => 'NOTES',
    				'name' => 'NOTES',
    				'type' => 'textarea',
    				'default_value' => '',
    				'placeholder' => '',
    				'maxlength' => '',
    				'rows' => '',
    				'formatting' => 'br',
    			),
    		),
    		'location' => array (
    			array (
    				array (
    					'param' => 'post_type',
    					'operator' => '==',
    					'value' => 'gg_trailers',
    					'order_no' => 0,
    					'group_no' => 0,
    				),
    			),
    		),
    		'options' => array (
    			'position' => 'side',
    			'layout' => 'default',
    			'hide_on_screen' => array (
    			),
    		),
    		'menu_order' => 0,
    	));
    }
    
  • Hi @brian-w
    Here is some sample code that may help in displaying custom post types in your page

    <?php
      $args = array(
        'post_type' => 'products',
        'post_status' => 'publish',
        'posts_per_page' => '10'
      );
      $products_loop = new WP_Query( $args );
      if ( $products_loop->have_posts() ) :
        while ( $products_loop->have_posts() ) : $products_loop->the_post();
          // Set variables
          $title = get_the_title();
          $description = get_the_content();
          $download = get_field(‘download’);
          $featured_image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
          $product_image1 = $featured_image[0];
          $product_image2 = get_field(‘product_image’);
          // Output
          ?>
          <div class=”product”>
            <img src=”<?php echo $product_image1;  ?>” alt=”<?php echo $title; ?>”>
            <h2><?php echo $title; ?></h2>
            <img src=”<?php echo $product_image1;  ?>” alt=”product-detail” class=”product-detail align-right”>
            <?php echo $description; ?>
            <p><a href=”<?php echo $download; ?>” target=”_blank” name=”Spec Sheet”>Download Spec Sheet</a></p>
          </div>
          <?php
          endwhile;
        wp_reset_postdata();
      endif;
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Can't display data on post’ is closed to new replies.