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 to show correct td of table tags in wp_query loop
- Exclude first post from wp query
- How could I prevent using the same custom loop in a template file when I only need to change one meta_query parameter?
- How to Generate a list of Most Commented post?
- 2 queries with counters
- limit number of post for achive page
- How to pick “full/thumbnail” images in the loop?
- foreach loop inside the loop creating duplicates in output
- Saving a post ID to use in a form elsewhere on website
- Create Div Wrapper On 3rd Iteration Or When Query Loop Items Run Out
- How to Fix an Archive.php That Displays All Posts?
- WordPress loop is not working
- Displaying Event within two given time frames
- Echo array value
- How to echo the_title from an array of posts?
- List all anchor links on a page
- Php code error in wordpress if else statements [closed]
- First post article different on Archives template
- How to add title attribute to archive items
- How to add ASCII symbol after each recent post [closed]
- Toolbar Hidden in a Virtual Page
- pagination broken – clicking next displays “page not found”
- Paginate pages with dynamic query
- displaying a fall back query if there’s nothing in the post-type category
- Strip from or something better?
- Display 3 posts with different HTML markup using a loop
- Limit the number of child pages
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- WordPress SQL JOIN query
- Using multiple variables to assign categories to an array
- Determine if ID is page or post and query the ID
- Custom template for password protected page
- How to create Loop code for Menu using WordPress?
- Add class to every other posts using get_posts
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- Custom Post Type Query W/Category Dropdown
- WP_Query and help with the loop for magazine front page
- Modifying WP URL handing code?
- Problem in replacing the_content with the_excerpt()
- WP_Query: How to get results from both meta_key options?