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

Custom Query: query by post custom meta data

Since you’re using WP_Query(), you should consult the Codex entry for WP_QUery(). It lists all of the parameters that can be passed to the arguments array.

In this case, you want to use the post custom meta parameters.

Assuming your custom meta key is _show_on_front, and your value is true or false:

<?php
$custom_query_args = array(
    'post_type' => 'Event',
    'posts_per_page' => 1000
    // INSERT POST CUSTOM META PARAMETERS HERE
    'meta_key' => '_show_on_front',
    'meta_value' => true
);
$custom_query = new WP_Query( $custom_query_args );
?>

For more complex examples, consult the linked Codex entry.

Related Posts:

  1. How can I sort homepage by a meta value?
  2. Limits, not all post are showen when querying for posts by view count
  3. searching by keywords in post’s metas or pagination links problem
  4. Can I exclude a post by meta key using pre_get_posts function?
  5. Custom post meta field effect on the performance on the post
  6. How to get custom post meta using REST API
  7. Difference between meta keys with _ and without _ [duplicate]
  8. Orderby meta_value only returns posts that have existing meta_key
  9. What is the index [0] for on post meta fields?
  10. What is “meta_input” parameter in wp_insert_post() used for?
  11. How to enable revisions for post meta data?
  12. The “_encloseme” Meta-Key Conundrum
  13. Best way to programmatically remove a category/term from a post
  14. Using get_post_meta with new_to_publish
  15. How to rename a custom field?
  16. How can I make wp-pagenavi work on a custom query built upon a form submission? [closed]
  17. Custom field metabox not showing in back-end
  18. Meta Query with AND & OR?
  19. So much data in postmeta
  20. Can I count the number of users matching a value in a multiple value key?
  21. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  22. How to hide meta box values from custom fields list?
  23. Auto sort the wp-admin post list by a meta key
  24. get_post_meta() unserialize issue – returns boolean(false)
  25. What is the advantage of the wp_options design pattern?
  26. Storing meta fields multiple times OR once with multi dimensional array?
  27. Allow user to create instances of custom field
  28. display specific custom fields
  29. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  30. Meta keywords and descriptions plugin for manually editing meta for each page/post
  31. passing argument to get_template_part() or a better way to code
  32. Is it possible to store arrays in a custom field?
  33. Get updated meta data after save_post hook
  34. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  35. Save HTML formatted data to post meta using add_post_meta()
  36. importing data from non-wordpress mysql db
  37. Create meta boxes that don’t show in custom fields
  38. Transients vs CRON +Custom Fields: Caching Data Per Post
  39. Unable to save datetime custom meta field using update_post_meta() function
  40. Up/Down voting system for WordPress
  41. post meta data clearing on autosave
  42. Create custom field on post draft or publish?
  43. Display info from custom fields in all images’ HTML
  44. Ordering posts by anniversary using only day and month
  45. get_post_meta fields don’t show up on posts page
  46. Update meta values with AJAX
  47. How to break meta values into different items and avoid duplicates?
  48. copy attachments to another post type and change attachment url
  49. Cannot edit post meta fields with rest API
  50. ajax delete value from custom field array
  51. Save attachment custom fields on front end
  52. How to use pagination with get_post_meta
  53. Copying Custom Meta Values from existing post to a duplicate post
  54. Add a post meta key and value only if it does not exist on the post
  55. Move value of one custom field to another
  56. Order posts according to user defined order for meta values?
  57. Displaying posts with only upcoming dates according their custom field date value
  58. Custom fields to save multiple values
  59. Custom fields: In what order are they saved into the DB?
  60. Function to change meta value in database for each post
  61. Get a post_id where meta_value equals something in a serialized meta_value field
  62. Get aggregate list of all custom fields for entire blog
  63. Plugin similar to Taxonomy Drill-Down for custom fields?
  64. Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
  65. Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
  66. Custom field value based on other custom field values
  67. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  68. How to save a ToggleControl value in a meta field?
  69. Which is best in the following scenario : post_meta vs custom table vs parent/child posts
  70. Saving custom image meta fields
  71. Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
  72. How do I query for a post by custom field?
  73. How to display Meta Field Value?
  74. MySQL query to set wp_postmeta using term_taxonomy_id value
  75. Count how many posts have a custom field set
  76. How to Validate Post Meta type/extension (Video File Image File etc)
  77. Get all meta keys assigned to a post type
  78. Upcoming Event: How do I sort database by custom date field, but ignore past dates?
  79. using multiple meta_key and meta_value in query_posts
  80. Custom Meta Box not Saving in Posts with Gutenberg Editor
  81. sort search results by custom fields using dropdown
  82. Adding custom fields (post meta) before/during wp_insert_post()
  83. Combine multiple custom field values into single value
  84. Get specific custom field keys from a post and put into an array
  85. Loop to display random posts only if a custom field matches category
  86. How do I use wp_query for WordPress search?
  87. Nav Menu – Add class based on meta keys
  88. How to query posts with certain custom meta data, and output Post data
  89. MySQL Query that looks for post with Custom Field, then changes Category
  90. Conditional custom field query
  91. ACF: How to get the full field name (meta_key) by a field key?
  92. How to wrap meta values seperated by comma in ? [closed]
  93. Display only past events on that page using Visual Composer Grid Bulider
  94. Bulk remove post meta
  95. post meta getting deleted on save
  96. How to create html block to display extra information on woocommerce single product page
  97. Can’t get post ID using wp_insert_post_data
  98. Custom Field Create Bulk via SQL Query
  99. Create Pop-Up Box with Custom Field Content Inside the Loop
  100. Unique Post Meta Values
Categories custom-field Tags custom-field, post-meta, query
Multiple Loops That Pull Pages (Child/Grandchild) While Styling the First Entry
Custom post type slideshow background images to insert in a plugin

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