Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Show posts from WP Custom Post Type selected from a field in a metabox

This issue has been solved by changing the code that displays posts a little.

<?php    
$albumsongs = get_posts( array('post_type' => 'song', 'numberposts' => -1, 'meta_key' => 'select_song_album', 'meta_value' => get_the_ID(),) );

foreach( $albumsongs as $post ){
setup_postdata($post);
?>
<div>
<span><?php the_title(); ?></span> <span><a href="https://wordpress.stackexchange.com/questions/352340/<?php the_permalink(); ?>">View</a></span>
</div>
<?php
}
wp_reset_postdata();
?>

Related Posts:

  1. How Can I save multiple records in same meta key?
  2. Update Post Meta for a logged in user
  3. Two Custom Post Types Many to Many Relationship
  4. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  5. Querying meta values within an array
  6. Check for custom field value in different post type than current one and do something
  7. Populate Custom Fields in a Custom Post Type?
  8. Adding dropdown select meta box to custom post type – seems restAPI is interfering
  9. WP_Query: include custom post type only with specific meta value
  10. Returning a list of custom post types excluding those without a specific meta_value
  11. Show the same Article Available in Other Categories
  12. Two near-identical custom field types – one works, the other doesn’t . What can cause this?
  13. Meta Key Value in current-user-only loop
  14. How to check if user meta field is empty in conditional else statement
  15. wp_query check if integer exists in custom field’s array
  16. Filtering custom post type on a combination of custom taxonomies and custom fields?
  17. Get posts between custom dates
  18. How to implement a Google map store locator
  19. Post image in WordPress not appearing on home page
  20. Meta query for custom post type ignored in main query
  21. Posting to a Custom Post Type from front end – user generated content
  22. Add custom field to Posts and sort by it
  23. A better way to add a meta box to custom post types
  24. get_post_meta not working on publishing
  25. Meta Query Not Returning Output Despite Having Matching Values
  26. Meta Query Filtering not working on Custom Meta Box using Radio Buttons
  27. How do I set all of a particular post meta to a value within the custom post type I’m in?
  28. Update postmeta Parent when post_status child change
  29. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  30. How to integrate a form (Ninja Form or Contact Form 7) with Custom Post Types?
  31. Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
  32. Meta Query posts not showing on ending date of custom field
  33. Admin Custom Meta Box – Pull Last 5 Posts from Custom Post Type
  34. How to Output which matched meta_keys were found from custom_type_posts?
  35. Possible to filter custom post type with multiple meta data?
  36. Importing Data from a Non-WordPress database, into WP
  37. filter search custom field query
  38. How to let users choose where to search for posts?
  39. Query based on custom fields start and end date
  40. Custom fields for custom post type
  41. Check if post with same meta value exists
  42. Submitting Custom Post Types with custom fields from Front-end form
  43. create custom meta box with default value
  44. delete_post_meta() for whole CPT / multiple posts?
  45. How to get specific post meta by title or id
  46. Getting a custom post’s custom field based on another custom post’s custom field select
  47. WP_Query of custom post type sorted by meta_key has unexpected results
  48. Batch Extract Date from post title and put into ACF custom field
  49. copy images from custom field to another custom field
  50. Custom Query: If One Post Object Field Value Is The Same As Another
  51. How to show custom field on specific custom post type posts only when filled
  52. Modify Posts from Custom_Post_Type within the plugin
  53. Cannot obtain custom meta information
  54. How can I output WPAlchemy repeating fields meta values in my page template?
  55. How to call a post’s metadata in shortcode.php?
  56. WP_Meta_Query object with conditionals
  57. delete duplicate meta_value with same post_id
  58. Search CPT Title AND Meta
  59. updating one custom meta field only
  60. Add a class to post_class if more than one post shares same meta_value_num
  61. Making a form for user to add new custom post with custom taxonomies and custom fields
  62. Add a meta field to the list of results for a custom post type
  63. Empty meta-box returns publishdate if no value is set?
  64. Front-end Image Upload to Custom Meta Box
  65. Filter search posts by post meta?
  66. Checking for custom field in admin pages
  67. A sports wordpress website
  68. Custom fields for post or terms which don’t update on post update
  69. Display custom post front end filter by ACF equals current user
  70. order the meta query results by 2 custom fields
  71. Custom Post Type meta data getting deleted on bulk editing taxonomies
  72. Get_post_custom not fetching value from array wordpress
  73. Add a form in every post and save data in post meta
  74. SELECT custom post type and its meta in SQL
  75. Using OR relation in meta_query to check for a value before sorting by another
  76. Save data is post using php front end
  77. How to display custom field in product description?
  78. How to keep custom post type related information
  79. Meta query and compare “!=” not working as expected
  80. Orderby if between two meta fields
  81. Use WP_query to match post types based on custom field values
  82. How can I add a meta[] to my custom post type and search by term with the Rest API?
  83. Creating an archive page or simple template to list all values of a custom field of specific post type listing
  84. Where is get_post_meta value located?
  85. Custom meta fields not showing up in WP_Response Object via custom endpoint
  86. meta query multiple values for the same key
  87. Sort custom post archives by a meta value from a different custom post type?
  88. Custom post types – meta_query: search lesson which starts sooner
  89. How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
  90. How to Disable option of meta field if that option is selected for any other post in custom post type?
  91. post type => ‘any’ not applied my custom queries
  92. How to get the posts that my following users are liked?
  93. Meta_Query refuses to return results
  94. Sort loop by custom field from different post type
  95. Meta_query by date for Events archive
  96. Add more custom fields when creating a new custom post type
  97. WP_posts (Not meta) extra custom field column show and change it in a custom post type
  98. update a posts of other custom post type
  99. How do I extract the contents of a CPT’s custom field for all posts?
  100. Query events post type after current date and timezone
Categories custom-post-types Tags custom-field, custom-post-types, meta-query, post-meta, posts
How much PHP and MySQL or MariaDB knowledge should I know to start writing WordPress themes and plug-ins and whatever else a beginner can edit?
Post Taxonomy Value get from User Field Value

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress