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

echo a specific meta_key queried through a custom post

OK so was way simpler than I thought in the end and didn’t involve a lot, just was approaching it in completely the wrong way:

The same can be achieved like this:

     /*GETING THE USERS FIRST PUBLISHED SUBSCRIPTION?? */
$useremail = $ticket['email'];
$user = get_user_by( 'email', $useremail );
$IDuser = $user->ID;
$args = array(
              'posts_per_page' => 1,
              'post_type' => 'subscription',
              'author' => $IDuser,
              'meta_key' => 'state',
              'meta_value' => 'complete',
              'orderby' => 'date',
              'order' => 'ASC',
              );
$first_post = new WP_Query($args);
//    '<pre>'.print_r($first_post).'</pre>'; // You can use this to check what the query produces to make sure you're on the right track.
if ($first_post->have_posts()) {
    $first_post->the_post();

    the_time('M j, Y');

    wp_reset_postdata();

That should give you the first published subscription belonging to $IDuser but can be used for any type of post if you change the 'post_type'

Related Posts:

  1. Orderby two meta fields not working
  2. How to only display posts whose meta_value field is not empty?
  3. Nested meta_query with multiple relation keys
  4. Can wp_query return posts meta in a single request?
  5. order by numeric value for meta value
  6. numberposts? showposts? posts_per_page?
  7. How do I query for posts by partial meta key?
  8. Use REGEXP in WP_Query meta_query key
  9. WordPress retrieving meta data for all custom post types in list view
  10. Order by optional meta key?
  11. meta_query: using BETWEEN with floats and/or casting to DECIMAL
  12. Reduce or prevent calling of update_meta_cache
  13. Is there a way to extend WP_query so Custom Post Types can have properties?
  14. What is the most efficient way of querying posts based on visits and date for current day?
  15. Getting attachments by meta value
  16. WP_Query displaying ALL posts
  17. How can I save an array from a random post sequence for later use?
  18. meta_query where value is equal to given value
  19. Query Custom Meta Value with Increment
  20. WP-CLI How to generate a list of posts with corresponding meta values
  21. All-in-One Event Calendar: Custom Query – Getting each event Instance [closed]
  22. Is there an action/filter called when WP_Query->query is finished and assigns posts
  23. Limit search results to exact match
  24. What is an efficient way to query based on post_meta?
  25. WP_Query not working as expected for attachments and custom meta_query
  26. How to count post meta key values for all posts in database
  27. Highlighting Sub topic in a post?
  28. Group posts by meta_key
  29. Pagination Not working on Home Page with 2 Query
  30. How should I use posts_where to change meta_value from a string to integer?
  31. Multiple keyword search
  32. How can I create a WP_Query that returns posts where one meta_value
  33. WordPress altering my custom query, How to fix it?
  34. WP Meta Query for some meta (array) values
  35. Hide posts with meta key in WP_Query
  36. Filter posts by comparing custom meta value against postdate
  37. WordPress query posts with multiple post_meta data
  38. WP_Query – Accessing MetaValue from Query Result
  39. search serialised meta_value for date value?
  40. How do I check if an article is popular this week?
  41. How to order posts on each different category?
  42. Get specific ACF key and value from all posts – no access to DB
  43. Woocommerce: order posts by meta key
  44. Order WP_Query results by meta key value in custom query
  45. How can I update post meta inside a WP_Query loop or the WordPress loop?
  46. Nested array issue in meta_query
  47. Display post meta conditionally based on it’s value
  48. Filtering by multiple conditions in the loop
  49. Sort by custom field that is an array?
  50. Custom wp_query – I’m getting ‘all’ post, not the specific post in the query
  51. Display count number of posts with the same specific meta_key meta_value
  52. meta_query with array as value with multiple arrays
  53. Query posts by searching for a string in a meta field
  54. WP_Query meta compare must include ALL array values
  55. Adding pagination to sub-wp_query within a singular post page
  56. Magazine style frontpage with multiple categories/loops and no duplicate posts
  57. How to make a query returning pages from multiple parents
  58. Prioritising and Ordering Posts By Category Name Using A Custom Loop
  59. Where is this query?
  60. How do i create a custom post query when the meta value is an array?
  61. wp query to use both author id and meta_query
  62. Sort by price wpdb
  63. Meta query ignores multiple values of the key
  64. Trouble with serialized metadata
  65. show most viewed post
  66. Delete post meta by serialized meta value
  67. How to use wp query in my custom page without including header and footer in wordpress
  68. Display posts from multiple value in meta separated by comma
  69. Custom filter from post meta
  70. Custom order revolution sliders post base slides as inserted in Specific Posts List field
  71. Why can my filter query SOME metadata but not other metadata?
  72. WP Query for all events prior to current date
  73. How to extend WP_query to a specific table?
  74. Query against multiple locations within single custom post type post
  75. Display the search results like the original pages
  76. update_post_meta performance in a loop woocommerce
  77. update_post_meta performance in a loop woocommerce
  78. How to set meta_query if get_post_meta returns nested array for that key? [duplicate]
  79. I need query_posts() to order results first by a meta value and then by post ID
  80. Multi line of $wpdb->query just run 1 time and end the loop right after
  81. Add to search posts query array with post IDS which will appear first
  82. Look for string in posts and postmeta
  83. Woocomerce – Order products by float attribute in archive pages
  84. Query postmeta based on meta_value, return array of post_id
  85. update_post_meta() not updating
  86. Multiple values in WP_Query : category__and
  87. I can’t get post based on its postmeta value and key
  88. How to set up pagination for a custom loop on a global template (author.php, tag.php, archive.php?)
  89. Saving custom fields for WP_Query to retrieve
  90. Meta key in wp_query bug?
  91. How to show all the associated posts with specific date of data metabox?
  92. Custom query using WP_Query is not working
  93. WP Meta Query at depth 2
  94. WP_Query with child element
  95. Sort by meta key within same day
  96. WP_Query Posts by Metadata from Option Tree
  97. Sorting Posts with meta value not working
  98. How to get several fields from wp_query?
  99. WP Query to order posts by multiple meta fields
  100. Return a single custom post from multiple meta queries
Categories wp-query Tags customization, post-meta, wp-query
Plugin templates vs Parent Theme
Show content of other domain inside WordPress

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