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

Limiting the amount of posts this displays

You have posts_per_page = -1, which means show unlimited posts. Change the -1 to the number of posts you want to appear.

Also you have output that skips if your “next_open_day” meta value is null, but the query will only run 3 times, so you need to move that logic into the query itself by using these arguments in the query_posts().

<?php
$metakey = 'next_open_day';
$args = array('post_type' => 'page',
              'post_parent' => 2,
               'posts_per_page' => 3,
               'orderby' => 'title',
               'order' => 'ASC',
               'meta_query' => array( 
                   array('key' => $metakey,
                         'value' => '',
                         'compare' => '!='
                   )
               )
);

query_posts($args);
?>

Related Posts:

  1. Order by meta value or date?
  2. Filtering posts by post meta data
  3. Custom query with query_posts doesn’t show post without certain meta_key
  4. How to sort by meta value?
  5. get_post_meta causes database queries
  6. Querying posts with meta value that begins with a certain pattern
  7. IF.. post meta show… Conditional Tag Help…?
  8. order posts by meta value on posts page
  9. Query_post($args)
  10. query_posts() on key’s value, or key’s existence
  11. How to retrieve an array of post IDs by a particular value stored in a custom meta’s array
  12. Query posts by meta_key whose value is an array
  13. Exclude posts by post meta value
  14. Frontend form with multiple posts
  15. query_posts orderby postmeta [closed]
  16. Ordering Posts By Meta Data
  17. get all posts with certain meta data
  18. How to Get All Posts with any post status?
  19. posts_per_page no limit
  20. what is the correct way to compare dates in a WP query_posts meta_query
  21. How can i get count from query post
  22. query_post by title?
  23. Why query_posts() isn’t marked as deprecated?
  24. Alternative to query_posts for main loop? [duplicate]
  25. how to query posts by category and tag?
  26. Using WP_Query to Query Multiple Categories with Limited Posts Per Category?
  27. How do I query by post format in WordPress 3.1
  28. Display posts of the last 7 days
  29. Is there a way to exclude the content from the post variable to save on RAM usage?
  30. How to query_posts using meta_query to orderby meta_key AND have a secondary sort by date?
  31. Query posts by custom taxonomy ID
  32. Display/query post formats
  33. How to query post by user role?
  34. How to return results of a get_posts() in explicitly defined order
  35. Help to condense/optimize some working code
  36. How to set posts per page using WP_Query()
  37. query_posts exclude a meta key
  38. How do I create a random post that will last for a day
  39. Ensuring sticky posts are retrieved first (without using two queries)?
  40. Determine if more posts are available than was asked for in `query_posts()`?
  41. Modify main WordPress loop with a parse_query filter
  42. query_posts() in function makes global $wp_query out of sync?
  43. Limiting query_posts to 1, regardless of sticky post?
  44. How to make “sticky” pages (and query by them)
  45. Query posts: how to exclude results if post is in multiple categories
  46. Query Custom Meta Value with Increment
  47. query_posts ->using meta_compare / where meta value is smaller or greater or equals
  48. Problem with ‘post__not_in’
  49. How to order posts by descending comment count on taxonomy page?
  50. Sort posts alphabetically by custom field value, insert divider between different letters
  51. Is it better practice to use query_posts, WP_Query, or get_posts to create various custom loops within a Page?
  52. WP 5.8 “Query Loop” block: where to place custom query?
  53. Sort X categories by last update and show image
  54. Custom Post Type “Event”: chronological list of recurring events
  55. using post__in allow duplicate post id
  56. Pagination on archive.php page
  57. WordPress Custom Query
  58. Best way to load page content in Fancybox popup?
  59. How should I intercept the main query and inject custom join / order by / group by criteria
  60. advice on creating a ‘related posts’ query like the one used on stackexchange
  61. order post my meta value m/d/y format with year as included value
  62. Order by meta value, pro first, then free
  63. Having trouble generating pagination links on custom query
  64. How to create an attachments archive with working pagination?
  65. _wp_page_template to dynamically use template
  66. Using dynamic conditions in ‘posts_where’ filter
  67. Help altering a query to exclude all but standard post format
  68. List users with the most total posts view
  69. Schedule Sticky Posts
  70. Use union/intersection query_posts variables in uri request parameter form?
  71. query_posts doesn’t order by title
  72. How to limit search to first letter of title?
  73. query_posts and pagination, still stuck after much research
  74. Query posts by taxonomy term name
  75. Sorting problem with ‘query_posts’ funcion in wordpress. Sort by custom field not working
  76. Total Count of Posts NOT in Selected Categories?
  77. how could I get the pagination as I want to when query posts using get_posts function
  78. Counter code for paginated category pages in wordpress
  79. Post Title displaying but not in the wrapped HTML I need
  80. Author List page: Exclude based on last post date
  81. WordPress Search Filter Only for Page with Child of Child of Child of Child of Child
  82. Replace query_posts with pre_get_posts
  83. query_posts sort in multiple directions
  84. Filter query_posts by tag slug on “Tag Archive” page (when tag is 2 or more words)
  85. pagination in author.php template returns 404 error
  86. How to display liked posts of current user in wordpress?
  87. Problem with single-page for my custom post
  88. How to ensure that is_search() return false after query_posts
  89. Warning: urlencode() expects parameter 1 to be string, array given in and not getting the preffered output
  90. How to modify the query to exclude posts by slug?
  91. query recent posts from several categories
  92. Inserting Post Using wp_insert_post. How to Fill Yoast Plugin SEO Fields
  93. Show Posts From Same Category OR Same Tag
  94. Post count per (day/month/year) since blog began
  95. Example Query Posts Showing the Latest Post with the Featured Image
  96. Dynamically excluding current page id
  97. Why is that gdsr_sort=thumbs (GD start rating plugin) only works with query_posts and not with WP_Query?
  98. How do i paginate query_posts with numeric pagination?
  99. Query_posts $query_string
  100. How to make the list of post and load on same page with sub-pages [closed]
Categories query-posts Tags post-meta, query-posts
Problem with get_post_meta
How to dispaly post informations (such as titles) in an admin plugin menu page?

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