You aren’t getting an image because you are calling the image field outside the query loop.
<?php $args = array(
'post_type' => 'slide',
'posts_per_page' => 1,
'orderby' => rand
);
// url = $image[0];
// width = $image[1];
// height = $image[2];
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$attachment_id = get_field('slide_photo');
$size = "medium"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
echo '<img src="';
echo $image[0];
echo '" />';
the_title();
the_field('slide_credit');
endwhile; ?>
Related Posts:
- How to extract images of post and pages excluding header and logo image in wordpress?
- how do i remove posts from a WP_Query so the pagination is right?
- Insert content of a post into another
- Redirect to another page using contact form 7? [closed]
- How to get a list of bundled products using wp_query in woocommerce
- Loop returns the current page’s permalink and guid instead of the post in the loop
- Multiple images per post – Show random image elsewhere
- Display content from custom post type if match to main post category
- Customize WooCommerce Product Images (Placement and size) [closed]
- How can i list random post from multiple category?
- How to generate video out of images via WordPress plugin
- Image gallery plugin [closed]
- Accessing post’s meta data based on user’s click of a post
- WooCommerce shop page orderby [closed]
- How to upload images to WP Panel keeping correct folder in FTP
- Inserting HTML tag with ACF into shortcode
- Images not showing after changing wp-content folder name
- Preview featured image using frontend post plugin
- How to add an image from web-link?
- Get posts from WP_Query and format them on admin_head
- Override global query results without hooks
- Not getting author rank when using return
- How to query the custom fields by language?
- How can I implement an Add to Collection function on my Image Gallery to be downloaded later?
- How do I “get the next 10 posts after post_id == x”?
- How to Delete all Unused photos Function
- How to resize images due to container width automatically server side/without CSS
- Use wordpress functions in another PHP file
- Set featured image randomly from WordPress Database on post submission
- Howto accurately position images with maximum flexibility?
- switched from query_posts to WP_query, not working now?
- AJAX search posts and pages
- Show an image in my header.php
- How to create a managed image repository in wordpress
- DROP TABLE with uninstall hook not working
- How can I restrict image upload dimensions for non-admin WordPress users?
- Fetch Children of Grouped Products Inside WooCommerce Product Loop
- How to change this WP_Query to get all ProductIDs and not only specific one?
- wp_generate_attachment_metadata is creating an empty array
- Force media library editor to overwrite the original filename?
- Contact Form 7 Get Image Function [closed]
- How generate 200% image size and save with suffix @2x
- Load external images via proxy
- How to call WordPress function other files
- Bulk edit WP posts to update embeded images with new alt tags
- How to upload WordPress Images to remote web server and display those images in WordPress gallery [closed]
- WP_Query and NULL meta keys
- Problem: wp_query outputs all images on site
- how to use in custom single.php template using php?
- Add padding while generating thumbnail
- Problem with the Loop – want to limit the access to three free articles
- WordPress page and plugin list using sql query
- Can we have an ‘Update metadata’ button in Image Gallery for all image instances?
- How to create a custom shortcode based on the layout?
- Using AJAX to generate front end / viewer end pages
- Retrieving Meta from Image Attachment
- Add ALT attribute to Pin It Button image to pass HTML5 validation
- Make change in media library affect images in published articles
- Adding (image) caching to my Tumblr widget
- How to upload multiple files/images when developing a wordpress plugin?
- Image Manager Plugin [closed]
- Implementing an image hosting website using WordPress? [closed]
- WooCommerce search products between price range using WP_Query
- ACF: post query, hide duplicate values [closed]
- Bulk Image Upload And Rerrange Functionality
- How to apply lazy loading in background images [closed]
- WordPress Plugin manipulate have_posts()
- Get User_id outside wordpress,
- How to insert multiple postmeta values with one query?
- Woocommerce showing images blurry in description page
- Slider/text combination plugin
- Plugin to hide image in excerpt
- Calling the_excerpt from inside a plugin template file
- Recent posts per category loop?
- How to Loop Through all Posts and Count Attachments using Get Media Attachments
- Import Instagram post to WordPress blog post
- Bulk update wordpress posts
- Image change on hover
- How to write “alt” tag in image for wordpress code?
- order posts by `meta_key`, Does not display posts that does not have `meta_key`
- Adding Static Image to WooCommerce Content-Single-Product template
- Where to find the code used to render a page that has a shortcode and a template defined?
- How do I get a post author’s image/avatar via RSS from another blog?
- WordPress Apply filter in plugin causes 500 internal error
- Meta query for comparing two dates
- In Woocommerce theme need to add custom external link [closed]
- Getting taxonomy images to display on single-post with their terms
- Replacing global wp_query
- Photo Gallery Plugin and Touch Devices
- Image crop, resize and compression plugin?
- How to Resize the Custom Post Images?
- Plugin that will let me specify a number of image sizes?
- How to limit image size for the entire website ? But without editing the post (css/plugin?!)
- Error in pdf generating plugin using FPDF
- Images under 1MB are not being compressed
- Skewed / slanted button within elementor [closed]
- How can I automatically download all images from all imported posts, place them on my new host, and replace all the links
- Return multiple values in a shortcode attribute
- Loop in elementor custom widget not working
- get_users(); Is an Undefined Function When Used in Cron Job