Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a website with a few custom post types. I have also installed Types plugin so I can use a custom field to upload/display images on the home page of the website. I've found that the code seems to have an issue with the custom post type.

If I add the code below the custom post type, the image doesn't appear. If I put the code above it, it appears. I have also tried removing the code and it will appear.

   <?php $pic_of_week = rg_get_social_pic_of_the_week(); 
                    $url = get_post_meta($pic_of_week['id'], 'social_pic_facebook_url', true);
                ?>

        <a id="social_image" href="<?php echo $url;?>" target="_blank">
            <div id="social_ofweek">
                <?php echo wp_get_attachment_image($pic_of_week['thumbnail'],'social-pic-of-the-week-thumbnail'); ?>
            </div>
            <img id="social_overlay" src="<?php bloginfo(stylesheet_directory); ?>/basemedia/images/socialpic2.png" alt="The Royal George Logo" /> 


        </a>    

    <?php echo(types_render_field("image_1", array("alt"=>"Product image",
  "width"=>"209","height"=>"298","proportional"=>"true"))); ?>

The code for the types plugin is -

<?php echo(types_render_field("image_1", array("alt"=>"Product image",
  "width"=>"209","height"=>"298","proportional"=>"true"))); ?>

The code that seems to be causing the issue is -

pic_of_week = rg_get_social_pic_of_the_week(); 
$url = get_post_meta($pic_of_week['id'], 'social_pic_facebook_url', true);
?> 

Can anyone tell me what the problem is?

Code for rg_get_social_pic_of_the_week() -

 if(!function_exists('rg_get_social_pic_of_the_week')) {
    function rg_get_social_pic_of_the_week() {
        global $wp_query;

        $args = array(
            'meta_key' => 'pic_of_the_week',
            'meta_value' => '1',
            'post_type' => 'social-pic'
        );
        $loop = new WP_Query($args);

        $social_pics_array = array();
        while($loop->have_posts()) {
            $loop->the_post();

            $social_pics_array[] = array(
                'content' => get_the_content(),
                'excerpt' => get_the_excerpt(),
                'id' => get_the_ID(),
                'thumbnail' => get_post_thumbnail_id(get_the_ID()),
                'title' => get_the_title()
            );
        }

        if(count($social_pics_array)) {
            return $social_pics_array[0];
        }

        return $social_pics_array;
    }
}
share|improve this question
    
what does the rg_get_social_pic_of_the_week() function contain? search your theme or plugins for that function to see what it does. –  Milo Aug 1 '12 at 0:07
    
Should I post the code for that function? –  Kim Harrison Aug 1 '12 at 1:24
    
I've added the code for the rg_get_social_pic_of_the_week() –  Kim Harrison Aug 1 '12 at 1:39
    
How about a link to the plugin? –  kaiser Aug 1 '12 at 1:54
    
plugin link wordpress.org/extend/plugins/types –  Kim Harrison Aug 1 '12 at 1:57
add comment

1 Answer

up vote 0 down vote accepted

You have to call wp_reset_postdata() after rg_get_social_pic_of_the_week(). it runs its own query which is polluting the global $post variable that other functions rely on.

share|improve this answer
    
Does that go on the home page or on the functions file? –  Kim Harrison Aug 1 '12 at 2:45
    
got it to work!! Thank you! –  Kim Harrison Aug 1 '12 at 3:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.