You should not use globals directly. There are some nice wrapper functions in the WordPress API. If you want to retrieve the ID of the current post or page just use get_the_ID().
Without any test … you could write the functionality in this way:
$file_id = get_post_meta( get_the_ID(), 'sound_s', true );
$file_url = wp_get_attachment_url( $file_id );
echo wp_audio_shortcode( [ 'src' => $file_url ] );
I don’t know much about the plugin that you use but why don’t you loop just over the list of posts:
$posts = get_posts();
foreach ( $posts as $item ) {
$file_id = get_post_meta( $item->ID, 'sound_s', true );
$file_url = wp_get_attachment_url( $file_id );
echo wp_audio_shortcode( [ 'src' => $file_url ] );
}
Related Posts:
- Build a content and excerpt grid loop with paging and options for # of posts
- Create a hierarchical loop at predefined markup requirements
- Pagination in category.php not functioning
- How do I exclude the current post from the upcoming post query
- Query multiple custom post types in single loop
- Inject post (from specific category) between posts in Loop
- Alter secondary loop to exclude posts from current page category
- Two posts in same div – WP loop
- how to display active, upcoming and past event with featured listing with pagination
- How to get to a specific position in wp_query?
- have_posts() execution failure
- Can’t search posts using WP_QUERY inside AJAX Function
- Using foreach loop breaks
- Using loop pagination on single.php
- Why WP_Query(‘showposts=5’) shows only 1 post?
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- WP_Query fails despite having 1 post
- wp_query get the 2nd post
- Display an image if odd number of posts in grid
- How to add div blocks after certain set of post
- How to overwrite orderby with add_query_var
- get_the_ID() in the footer returns wrong value
- change the default order of posts only for specific categories
- Get all posts as an array ID => Name
- WP_Query multiple post results
- Do not duplicate posts with multiple categories in multiple loops
- Infinite Loop – WP_Query
- Posts are not looping through correctly
- Dividing the loop to style post differently
- How to extract information from a wp_query result?
- posts_nav_link pulling in multiple post types
- Remove Post if Advanced Custom Field is checked to fix paging
- How to break up php code to avoid echo
- Search.php gets metadata from first post
- the_post(); prints out style text into my HTML?
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- Wp Query : Order by distance lat,lon
- search.php to search only the post title
- in_array not working on dev server but works on localhost
- WordPress sorting posts by date and title using a dropdown
- Is there anyway I can call the year once?
- How to display sticky post always at the top (before regular post) in wordpress?
- Making list of posts with chosen description
- My query keeps looping infinitely ! how to stop it?
- Efficient way of querying for a “fallback” post?
- For each 3 posts, show a different post type
- Div Missing In Custom Loop Query
- Add post class in custom loop (WP_QUERY)
- Automatically create a loop for post ID
- Advanced Taxonomy query, with 3 post types
- Custom query_posts() parameter
- Why does a meta_query break this WP_Query?
- Does wp_query and query_posts affect website performance? [duplicate]
- WordPress post pagination on custom template not working
- How to modify this function to exclude also the post belonging to a specific category?
- /page/2/ redirect to 404
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- How do I display WooCommerce products in my query to rows of 3?
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress
- How do I use WP_query with multiple post IDs?
- Some doubts about how the main query and the custom query works in this custom theme?
- Passing JSON data from WP Query into AJAX causing NULL errors
- How to order posts by modified date without using ‘query_posts’?
- Want to separate sections of posts. Can you restart loop?
- How to add 2 posts under another post? Formatting should be intact
- How to display custom field on homepage
- Get taxonomy terms only of the WP_Query current posts
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- How to securely provide a $_POST var in WP_Query with PHP 7?
- Create WP_Query to search for posts by their categories or their parent/child categories
- Multiple loops without repeating content
- If Query In Sidebar
- Checking array against author id in loop
- How do I Turn This Into An if statement?
- Widgets in the loop if active
- How to get all author posts outside of author templates
- How can I group posts by months and years?
- Custom Pagination is Broken
- Limit tags shown in post
- Create Div Wrapper On 3rd Iteration Or When Query Loop Items Run Out
- How to echo the_title from an array of posts?
- Add class to every other posts using get_posts
- Using a new WP_Query inside the loop
- Display articles with a different template in the home page | Solved |
- Looping through dummy posts and showing them in the main index.php
- ACF – Get ID of relationship field in flexible content
- WordPress Ajax filter: Create two loops for different output styles?
- Problem with my loops
- Return to the beginning of the results of a for loop
- Thumbnail wouldn’t scale to size properly
- How to sort (orderby) a query done by a template function before the ‘foreach’ loop?
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Retrieving specific images from Media Library
- direct query to post_meta table
- Adding unique marketing messages between certain products whilst using isotope/Infinite Scroll
- List sibling pages widget, exclude current page
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- Options.php loop won’t show!
- Show number of posts AND number on current page (cannot make it work)