Tagged: , , ,

Viewing 5 reply threads
  • Author
    Posts
    • #2255
      tuckerjoenz
      Participant

      Ok, I’ve been doing some digging and seen a few posts like this one for example, on how to get my images to show up in a preview/page on the frontend. I’m not getting it to work for any of my Custom Post Types. I need a little help on how to get these to show up. Here is a couple of my custom post types.

      STORIES

      <?php
      /*
      Title: Stories of Impact
      Post Type: stories
      Order: 14
      Meta Box: false
      Collapse: false
      */
      ?>
      
      <?php
      
        piklist('field', array(
          'type' => 'file'
          ,'field' => 'story_media'
          ,'scope' => 'post_meta'
          ,'label' => __('Media Uploader','story-media')
          ,'description' => __('Validation rule set: Upload no more than two files.','story-media')
          ,'options' => array(
            'modal_title' => __('Add File(s)','story-media')
            ,'button' => __('Add','story-media')
          )
        ));
      
        piklist('field', array(
           'type' => 'datepicker'
           ,'field' => 'story_date'
           ,'label' => 'Story Date'
           ,'description' => 'Click in box'
           ,'attributes' => array(
             'class' => 'text'
           )
          ,'options' => array(
             'dateFormat' => 'M d, yy'
             ,'firstDay' => '0'
          )
        ));
      
        piklist('field', array(
          'type' => 'editor'
          ,'scope' => 'post'
          ,'field' => 'post_content'
          ,'template'=>'field'
          ,'label' => 'Add Story'
          ,'description' => 'Stories of Impact'
          ,'options' => array (
            'media_buttons' => true
            ,'teeny' => true
            ,'textarea_rows' => 5
            ,'drag_drop_upload' => true
          )
        ));'
      
      <strong>EVENTS</strong>
      
      

      <?php
      /*
      Title: Event Information
      Post Type: events
      Order: 6
      Meta Box: false
      Collapse: false
      */

      <?php

      piklist(‘field’, array(
      ‘type’ => ‘select’
      ,’scope’ => ‘post_meta’
      ,’field’ => ‘event_type’
      ,’value’ => ‘option1′
      ,’label’ => ‘Event Type’
      ,’description’ => ‘Future or past event.’
      ,’attributes’ => array(
      ‘class’ => ‘text’
      )
      ,’choices’ => array(
      ‘option1’ => ‘Future Event’
      ,’option2′ => ‘Past Event’
      )
      ));

      piklist(‘field’, array(
      ‘type’ => ‘file’
      ,’field’ => ‘event_upload’
      ,’scope’ => ‘post_meta’
      ,’label’ => __(‘Event Photo’,’piklist-demo’)
      ,’options’ => array(
      ‘basic’ => true
      )
      ));

      piklist(‘field’, array(
      ‘type’ => ‘file’
      ,’field’ => ‘event_media’
      ,’scope’ => ‘post_meta’
      ,’label’ => __(‘Media Uploader’,’piklist-demo’)
      ,’description’ => __(‘Validation rule set: Upload no more than two files.’,’piklist-demo’)
      ,’options’ => array(
      ‘modal_title’ => __(‘Add File(s)’,’piklist-demo’)
      ,’button’ => __(‘Add’,’piklist-demo’)
      )
      ));

      piklist(‘field’ ,array(
      ‘type’ => ‘group’
      ,’label’ => ‘Dates (From – To)’
      ,’fields’ => array(
      array(
      ‘type’ => ‘datepicker’
      ,’field’ => ‘date_from’
      ,’label’ => ‘Date: (from)’
      ,’options’ => array(
      ‘dateFormat’ => ‘M d, yy’
      ,’changeYear’ => true
      )
      ,’attributes’ => array(
      ‘class’ => array(‘date’)
      ,’size’ => 12
      )
      ,’columns’ => 6
      ,’value’ => date(‘M d, Y’)
      )
      ,array(
      ‘type’ => ‘datepicker’
      ,’field’ => ‘date_to’
      ,’label’ => ‘Date: (to)’
      ,’options’ => array(
      ‘dateFormat’ => ‘M d, yy’
      ,’changeYear’ => true
      )
      ,’attributes’ => array(
      ‘class’ => array(‘date’)
      ,’size’ => 12
      )
      ,’columns’ => 6
      ,’value’ => date(‘M d, Y’)
      )
      )
      ));

      piklist(‘field’, array(
      ‘type’ => ‘text’
      ,’field’ => ‘event_link’
      ,’label’ => ‘Event Link’
      ,’attributes’ => array(
      ‘class’ => ‘regular-text’
      ,’placeholder’ => ‘http://&#8217;
      )
      ,’on_post_status’ => array(
      ‘value’ => ‘lock’
      )
      ));

      piklist(‘field’, array(
      ‘type’ => ‘checkbox’
      ,’field’ => ‘show_hide_checkbox’
      ,’label’ => ‘Arcus Event:’
      ,’choices’ => array(
      ‘show’ => ‘Show’
      )
      ,’on_post_status’ => array(
      ‘value’ => ‘lock’
      )
      ));

      piklist(‘field’, array(
      ‘type’ => ‘editor’
      ,’scope’ => ‘post’
      ,’field’ => ‘post_content’
      ,’template’=>’field’
      ,’label’ => ‘Add Event’
      ,’description’ => ‘Event information’
      ,’options’ => array (
      ‘media_buttons’ => true
      ,’teeny’ => true
      ,’textarea_rows’ => 5
      ,’drag_drop_upload’ => true
      )
      ));

      piklist(‘field’, array(
      ‘type’ => ‘post-relate’
      ,’scope’ => ‘Partners’
      ,’template’ => ‘field’
      ));`

      and this is my single post code:

      get_header();
      ?>
      
      	<div id="sidebar_layout" class="clearfix">
      		<div class="sidebar_layout-inner">
      			<div class="row grid-protection">
      
      				<!-- <?php get_sidebar( 'left' ); ?> -->
      
      				<!-- CONTENT (start) -->
      
      				<div id="content" class="<?php echo themeblvd_get_column_class('content'); ?> clearfix" role="main">
      					<div class="inner">
      						<h1>TEST</h1>
      						<?php
      						$settings = get_option('my_settings');
      						$story_media = $settings['story_media']; ?>
      
      						<?php
      						foreach ($story_media as $image)
      						{
      						  $myupload = get_post($image);
      						  $title = $myupload->post_title;
      						  $description = $myupload->post_content;
      						  $caption = $myupload->post_excerpt;
      
      						  echo 'title:' . $title;
      						  echo 'description:' . $description;
      						  echo 'caption:' . $caption;
      
      						 echo '<img src="' . wp_get_attachment_url($myupload- />ID) . '"/>';
      
      						  print_r($myupload); // Displays all data
      						}
      						?>
      
      						<?php themeblvd_content_top(); ?>
      
      						<?php while ( have_posts() ) : the_post(); ?>
      
      							<?php get_template_part( 'content', themeblvd_get_part( 'single' ) ); ?>
      
      							<?php themeblvd_single_footer(); ?>
      
      							<?php if ( themeblvd_supports( 'comments', 'posts' ) ) : ?>
      								<?php comments_template( '', true ); ?>
      							<?php endif; ?>
      
      						<?php endwhile; ?>
      
      						<?php themeblvd_content_bottom(); ?>
      					</div><!-- .inner (end) -->
      				</div><!-- #content (end) -->
      
      				<!-- CONTENT (end) -->
      
      				<?php get_sidebar( 'right' ); ?>
      
      			</div><!-- .grid-protection (end) -->
      		</div><!-- .sidebar_layout-inner (end) -->
      	</div><!-- #sidebar_layout (end) -->
      
      <?php get_footer(); ?>
    • #2256
      Steve
      Keymaster

      Your file code is being shown on a Post Type, but you are using get_option to pull the data, $settings = get_option('my_settings'); get_option is used for settings.

      In the tutorial you referenced, it shows how to get data for a post type using get_post_meta: $image_ids = get_post_meta($post_id, 'my_image');

    • #2257
      tuckerjoenz
      Participant

      Thanks for that, but still not getting it to work. Here is what I got now:

      <?php
      
        $image_ids = get_post_meta($post_id, 'my_image');
      
        foreach ($image_ids as $image)
        {
          $myupload = get_post_meta($image);
      
          echo '<img src="' . wp_get_attachment_url($myupload->ID) . '"/>';
      
          print_r($myupload); // Displays all data
        }
      ?>

      I’m just wondering how to get the single.php to pull in upload images from any custom post type when clicking on the “view post” button to preview. Thanks!

    • #2258
      Steve
      Keymaster

      @tuckerjoenz

      A few things:
      1) There was a typo in the doc. Try this: echo '<img src="' . wp_get_attachment_url($image) . '"/>';
      2) Unfortunately, you just can’t blindly copy the docs, because your code will probably be different. $image_ids = get_post_meta($post_id, 'my_image');, means get the post meta field ‘my_image’, however, you don’t have a field called ‘my_image”, yours is called ‘story_media’. You will need to change that as well.

    • #2260
      tuckerjoenz
      Participant

      Excellent! Thanks Steve this helped!

    • #2261
      Steve
      Keymaster

      Great. Closing ticket.

Viewing 5 reply threads
  • The topic ‘Images on previews of Custom Post Types not showing’ is closed to new replies.