Hey mistercyrill,
We’ll need to check that the custom post type supports custom fields. How are you passing the $post_id to the function?
Hey Jacob,
I’m using : <?php echo apply_filters('the_content', get_post_meta($post->ID, 'bg_images', true)); ?>
and the i’m trying to pick it up in here :
function fullscreenBG() {
global $post, $anything_slides;
$post_id = $post->ID;
$attached_images = get_post_meta($post_id, 'bg_images', true);
if ( $attached_images != '') :
$fit_always = true;
$ss_interval = 5;
$ssfx = 1;
?>
I’ve tried a few different methods but can’t get anything to return a value.
Any thoughts?
Ok so apparently, I can fetch the content from a page or post but not from the “anything_slides” custom post type…
Is there a way to fix that? Can this have something to do with the way I fetch the id?
Thanks,
C.
mistercyril, what is value of your custom field ‘bg_images’, is it a field with a single value or field with multiple values? How did you created this custom field?
This is how I made it. I use meta-box (https://github.com/rilwis/meta-box) plugin where uploaded images ID’s are saved as a field with multiple values. So first I need to check all values from array, then reset array and get only first value. Further, each uploaded image is treated as an attachment so I need to use wp built-in function to get image URL.
here is my code:
global $post;
$post_id = get_post_custom($post->ID);
$slide_bg_array = get_post_meta($post->ID, "custom_meta_slide_bgimg", false);
global $wpdb;
if ( !is_array( $slide_bg_array ) )
$slide_bg_array = ( array ) $slide_bg_array ;
if ( !empty( $slide_bg_array ) ) {
$slide_bg_array = implode( ',', $slide_bg_array );
$images = $wpdb->get_col( "
SELECT ID FROM $wpdb->posts
WHERE post_type = 'attachment'
AND ID IN ( $slide_bg_array )
ORDER BY menu_order ASC
" );
$image = reset($images);
} else {
$image = "";
}
$imgsrc = wp_get_attachment_image_src( $image, 'full' );
$imgsrc = $imgsrc[0];
$slide_bgimg = "url(". $imgsrc .")";
And later I changed output. As you can see I use many other custom fields and everything works great.
$output .= "<div style='background-image:" . $slide_bgimg . "; background-color:" . $slide_bgcolor . "; width: 100%; height: 100%;' class='content clearfix'>" ;
$output .= do_shortcode($content) ;
$output .= "<h1 class='entry-title-slider1 slide_1'><a href=". $blaurl ." >" . $bio . "</a></h1>";
$output .= "<div class='post-category slide_2'>" .$field_1. $field_2. "</div>";
$output .= "</div>";
Hope this helps.
Now I see my code is to long. I put it on pastebin http://pastebin.com/K99B5G4a