Support

Account

Forum Replies Created

  • Ah ha! That worked!

    <?php global $post;
    	$values = get_post_meta( $post->ID, 'photos');
    	$images = wp_get_attachment_image_src( $values[0][0], 'project-thumb' ); ?>
    
    <div class="main-photo"> 	
    	<img src="<?php echo $images[0]; ?>"/>  
    </div>
  • Elliot,

    Yes, your description of the problem is correct.

    Creating a new gallery with a new name did not change anything. I work for a web development company, and we make our own themes so I didn’t think there would be a filter like that, but I tried it anyway. Any other ideas?

    Thanks for your help!

  • Yes, I mean category.php is using code from content-project.php to display a preview of a custom post type. archive-project.php is also using this same code from content-project.php to display the same preview on an archive page. They are both pulling the template code via get_template_part('content', 'project');. Every field for a project cpt can be displayed except the gallery field when viewing a category. That is the only field that doesn’t work, and only when viewing a category.

  • I believe so. That outputs an empty array. The name ‘photos’ must be correct since they display fine on the archive page.

    If I replace the ‘photos’ with any other custom field name for that post, that displays fine.

    If I don’t use the $post->ID parameter, the photos still display fine on the archive page, but not for the category pages.

    I tried moving the code from the content-project.php template to both the archive and category pages, still no changes.

    Why would two pages, using the same code, display one custom field differently?

  • I don’t know if this will help, but I printed the values using two methods: get_fields and get_post_custom.

    get_fields:

    <?php $fields = get_fields( $post->ID );?>
    <pre> <?php var_dump($fields) ?> </pre>

    Printed:

    ["photos"]=>
    array(0) {
    }

    get_post_custom:

    <?php $images = get_field(‘photos’, $post->ID );?>
    <pre><?php $c = get_post_custom(); var_dump($c); ?></pre>

    Printed:

    ["photos"]=>
    array(1) {
    [0]=>
    string(62) “a:4:{i:0;s:3:”123″;i:1;s:3:”125″;i:2;s:3:”124″;i:3;s:3:”126″;}”
    }
    ["_photos"]=>
    array(1) {
    [0]=>
    string(19) “field_51dad81f8f6b2″
    }
  • Yes, I used
    echo $post->ID;
    and it prints the correct ID for the post.

  • Yes, I have tested that as well, and it is correct. I also used this code to display the values of all the fields:

    $fields = get_fields( $post->ID );?>
    		<pre> <?php var_dump($fields) ?> </pre>

    I then compared the output on both the archive page and category pages. Everything is the same except on the archive page, the “photos” field shows an array filled with different photos and sizes, whereas the output on the category pages has a completely empty array.

    ["photos"]=>
      array(0) {
      }
Viewing 7 posts - 1 through 7 (of 7 total)