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

Display all custom post type posts and order them by an optional meta_key

<?php
// query posts
$query_property = query_posts( array( 
     'orderby'    => 'date meta_value' // orderby date AND meta value
) );

// First loop
$query_feat = $query_string.'&meta_value=on&meta_key=property_featured';
// Offset for second loop
$query_all = $query_string.'&offset=3&meta_key=property_featured';

// First loop
if ( $query_feat->have_posts() : while ( $query_feat->have_posts() ) : # etc....
    // do stuff
endif;

// Second loop
if ( $query_all->have_posts() : while ( $query_all->have_posts() ) : # etc....
    // do stuff
endif;
?>

Related Posts:

  1. Can the Next/Prev Post links be ordered by menu order or by a meta key?
  2. Correctly delete posts with meta and attachments [duplicate]
  3. Storing revisions of metadata for custom post type
  4. Custom Post type – how to get checkbox to update meta field to null
  5. Ordering posts having multiple post-meta date fields
  6. Custom Post Type with Input fields to seperate table on database.
  7. How Can I save multiple records in same meta key?
  8. Permalinks using event date (year & month) instead of publication date
  9. Grossly inefficient wordpress loops!
  10. How Do I Use WP_Query to Run This Database Query as Search Result?
  11. Creating a custom post type upon registration
  12. Reason action hook won’t work with update_post_meta from frontend form? Alternative?
  13. how to make custom posts sticky? [duplicate]
  14. Showing Meta Data for Custom Post Types?
  15. Having trouble with custom post type / meta box
  16. Query for posts from any post type but only add instock products
  17. update custom post type meta from a shortcode
  18. How to make custom post meta wp_editor translatable?
  19. How to keep a check box in custom meta box for custom post type checked by default for add new post?
  20. Show metabox in custom-post-template depending on taxonomy term?
  21. ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
  22. update_post_meta() whenever custom post type is updated
  23. Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
  24. Using date stored as custom field to filter posts displayed in admin
  25. How to best delete orphan wp_postmeta
  26. How can I get_post_meta() in the most efficient way?
  27. Count posts with specific term_meta
  28. Custom search for custom post meta with pre_get_posts interferes with WP search
  29. WordPress Orderby Numeric Value Not Working
  30. Replace title column in post list with post meta value
  31. My theme saves their custom post type’s metadata as a serialized array, how to access the keys?
  32. List all images from a single post meta value
  33. Does WordPress limit the length of slug names for Post Meta or Terms?
  34. Insert Multiple Post with Same Publish Button
  35. Undefined Variable – Custom Post Type Meta
  36. Ordering posts in Search & taxonomy by post_meta
  37. Meta Key Value in current-user-only loop
  38. How can I make a custom post type sticky?
  39. How to implement a Google map store locator
  40. Post image in WordPress not appearing on home page
  41. changing meta value and meta key of price field
  42. Posting to a Custom Post Type from front end – user generated content
  43. Getting meta in editor plugin, and event triggering issue
  44. Restrict Access to Posts based on Custom User and Post Meta Data
  45. get_post_meta returning no value in custom post type alert email
  46. Metabox not show in categories custom post type cmb2
  47. Custom fields for custom post type
  48. Show future events based on custom field AND order by date
  49. Is there a way to exclude posts based on meta_values?
  50. Submitting Custom Post Types with custom fields from Front-end form
  51. How to Echo Metadata Value in Currency Format
  52. Issue on Working with Metabox – Checkbox to enable Sale Items
  53. Filter posts by tax (dropdown) and meta value
  54. Publish and save specific postmeta to a filtered post_type
  55. Why do I have to press the “Update” button twice to save my meta box values?
  56. Batch Extract Date from post title and put into ACF custom field
  57. How to handle this specific case of custom post type?
  58. Save CTP post meta different values each day without overwriting previous values
  59. get_post_meta returns NULL in front-end, but correct result in back-end
  60. Meta box data is saved but NOT displayed in the meta box text field. Why?
  61. How to call a post’s metadata in shortcode.php?
  62. Sanitaizing Select Optin For Custom Post Type Metabox in WP
  63. HM CMB: Post Select Field for CPT ID
  64. Getting WordPress to store 0 values for custom post type meta
  65. updating one custom meta field only
  66. Problem Saving Custom Post Type Meta Values
  67. Get_post_custom not fetching value from array wordpress
  68. Save data is post using php front end
  69. Creating a custom post type upon registration for a specific user role
  70. How to sort by multiple values in a nested WP_Query
  71. Show posts from WP Custom Post Type selected from a field in a metabox
  72. Where is get_post_meta value located?
  73. How do I create a customised table list of a custom post type (in the admin area)?
  74. Staggering featured post using ‘sticky’
  75. add action save post type and update post meta woocommerce
  76. get_post_meta not working with variable as a post_id for dynamically get the postid
  77. How to save post_status using action save_post?
  78. Custom post meta box as a sub form
  79. Metaboxes in Loop
  80. Add more custom fields when creating a new custom post type
  81. Custom meta box data not saving
  82. Collect custom post in a calendar
  83. Storing data in a multidimensional array from dynamically generated foreach loop
  84. Edit is changing my custom’s post type parent id
  85. Disable Facebook Comments Automatically On CPT
  86. Problem with ‘save_post’ hook not running
  87. WordPress custom post type
  88. Edit post meta direct from post.php?
  89. Howto: use existing post_meta as options for a different metabox (checkboxes or list)
  90. Values inside a custom field to determine which category posts to display
  91. How to rewrite CPT-Permalinks the correct way (incorporating meta-box-data)?
  92. Advanced search form with filters for custom taxonomies and custom fields
  93. Top 30 Songs using Custom Post Type
  94. Advice Needed for Post Meta Database Efficiency
  95. Querying meta values within an array
  96. Custom post type – update_meta not working
  97. why get_post_meta is returning 0?
  98. Save post_parent in a custom post type
  99. Update an existing post in a custom post type
  100. getEntityRecords/useEntityRecords: How to use CPT metadata?
Categories custom-post-types Tags custom-post-types, post-meta, sticky-post
Mass Import Users without sending new user notification
Set Image width=’x%’ (percentage width not pixel width) when inserted via the media manager?

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