php - Retrive Image URL of Custom Fields in Theme -
i have created custom fields custom post type. when retrieve values in theme template image value returning 22. how can image url.?
<?php $args = array( 'posts_per_page' => -1, 'post_type' => 'projects', 'post_status' => 'publish', ); $projects = get_posts( $args ); foreach ($projects $project) { echo $project->project_title; // title text echo $project->project_description; // description content echo $project->project_image; // 22 } ?>
when print $project
wp_post object ( [id] => 35 [post_author] => 1 [post_date] => 2017-04-07 05:50:29 [post_date_gmt] => 2017-04-07 05:50:29 [post_content] => tekzenit [post_title] => tekzenit [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => tekzenit [to_ping] => [pinged] => [post_modified] => 2017-04-07 06:12:54 [post_modified_gmt] => 2017-04-07 06:12:54 [post_content_filtered] => [post_parent] => 0 [guid] => http://10.180.82.8/fareed/?post_type=projects&p=35 [menu_order] => 0 [post_type] => projects [post_mime_type] => [comment_count] => 0 [filter] => raw )
some more info helpful on how created custom fields if used advanced custom fields or wrote code yourself.
but if have image id can use:
$img_id = $project->project_image; $img_array = wp_get_attachment_image_src($img_id, 'full' ); $img_url = $img_array[0]; echo $img_url;
Comments
Post a Comment