<?php
// the query
$loop = new WP_Query( array( 'post_type' => 'features', 'orderby' => 'post_id', 'order' => 'ASC' ) ); ?>
<?php if ( $loop->have_posts() ) : ?>
<!-- the loop -->
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<img src="<?php the_field('image'); ?>">
<?php endwhile; ?>
<!-- end of the loop -->
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
I have a problem with adding image to loop. I create an custom image field assigned to custom post type "features" and I want to add this image field to loop. This way is bad becouse in console in src="" is:
http://localhost/konkursy/wp-content/uploads/2019/01/smartphone_samsung.png, http://localhost/konkursy/konkursy_internetowe/caruzela-1/smartphone_samsung/ , balbla, 1, sad, asd, smartphone_samsung, inherit, 56, 2019-01-02 10:56:12, 2019-01-02 12:06:21, 0, image/png, image, png, http://localhost/konkursy/wp-includes/images/media/default.png , 200, 150, Array">
I don't know how to do this with array becouse this field is assigned to post type not to template page
<?php
$image = get_field('image');
?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
This way is not working
Maybe someone who wants to help me can help this: https://www.advancedcustomfields.com/resources/image/
Problem solved.
In adv custom field options you can change array to URL;
or second option: add array to loop not to WP_Query like (like I so far)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.