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 post type submenu sorted by specific meta_key & meta_value

Meta key or meta value in query parameter doesn’t automatically filter the query by default. So you have to filter the query to restrict results.

add_filter('pre_get_posts', 'restrict_events_by_meta');
function restrict_events_by_meta($q){
    if( 
        $q->is_main_query() 
        && is_admin() 
        && 'event' == $q->get('post_type') 
        && isset( $_GET['meta_key']) 
        && isset( $_GET['meta_value']) 
    ){
        $q->set('meta_key', $_GET['meta_key'] );
        $q->set('meta_value', $_GET['meta_value'] );
        $q->set('orderby', 'meta_key' );
    }
}

Related Posts:

  1. Query all posts where a meta key does not exist
  2. what is the correct way to compare dates in a WP query_posts meta_query
  3. How to Add a Sub Menu Page to a Custom Post Type?
  4. Get post with multiple meta keys and value
  5. Admin Area Custom Type Search By Meta Fields Without Title & Content
  6. Echo all meta keys of a custom-post TYPE
  7. How to give position to Submenu under custom post type
  8. Post metadata deletes itself
  9. Add Settings to Custom Post Type
  10. Custom Post Type: Set post_title equal to a custom post type field
  11. I can’t set meta_key in my custom post type query
  12. How can I include meta box content when searching?
  13. update a post meta from a single table cell TablePress
  14. Custom Meta Boxes – Nonce Issue – Move to trash issue
  15. Automatically adding meta data to posts or multiple query help
  16. Trigger “unsaved changes” dialog for custom post meta changes
  17. Conditionally Query Custom Post Types by Post Meta for Blog Home Page?
  18. Displaying custom posts only if custom meta box’s date is not expired
  19. Displaying Metabox value (custom post type taxonomy)
  20. How do I sort a custom post type admin column using two meta keys?
  21. How can I display my custom metaboxes on a custom post template?
  22. get_post_meta is returning image id
  23. Custom Post Type, Saving Multiple Checkboxes
  24. Create a random unique 6 digit number as custom field for custom post type
  25. Export entries and multiple custom field meta to .csv?
  26. how to interconnect custom post types?
  27. orderby in custom WP Query does not work
  28. Insert post metadata for all posts in CPT at once if metadata no existent
  29. Display custom post type from dynamic custom field
  30. Insert & order custom post types in/as submenu
  31. Populate dropdown from one custom post type inside another custom post type
  32. Notice: Undefined index: error and understanding wordpress
  33. Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
  34. Get posts between custom dates
  35. Deleting Custom Posts & Meta Data on Uninstall
  36. How do I create an archive page as a including metadata?
  37. Two Custom Post Types Many to Many Relationship
  38. how can I register a post_meta field in an existing CPT and then call it again with get_post_custom()?
  39. post meta parameter in post custom-post-type endpoint with restapi
  40. Update postmeta Parent when post_status child change
  41. Update database from Quick Edit according to Checkbox state of Custom Post Type
  42. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  43. Storing a many to many post type relationship in post meta and keeping SQL ability for Joins
  44. Dynamic Custom Fields
  45. Show Custom Post Type meta boxes only on Page Edit
  46. Custom filter function not working with Custom post type
  47. Importing Data from a Non-WordPress database, into WP
  48. List Taxonomies: Don’t list taxonomy if it has no post – depending on custom post-meta?
  49. Meta Data for Custom Post Type not saving
  50. Check if post with same meta value exists
  51. Get only used meta_values
  52. Do posts, pages and / or custom post type objects have unique ID numbers or can there be multiple objects with the same IDs?
  53. Archieve.php not loading for custom post type
  54. Create Array from custom post type to display a slider
  55. Setting Post Title via Meta Data returns Auto-draft
  56. Values from meta-box not on $_POST
  57. Returning a custom content types with meta values
  58. copy images from custom field to another custom field
  59. Cannot obtain custom meta information
  60. How can I output WPAlchemy repeating fields meta values in my page template?
  61. Save Metabox Custom Field Value
  62. Meta box data not saving
  63. How can I get some of a posts meta data whilst it is still inserting?
  64. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  65. best way to use custom taxonomy, post type and meta in a job system
  66. Empty meta-box returns publishdate if no value is set?
  67. Building tags and archive using meta from custom post type
  68. How to order custom posts by one of the custom fields value, ‘date’?
  69. Custom Meta Box with variable number of fields
  70. Hide title field of selected post-types on edit pages
  71. WordPress CPT Taxonomy Dashboard Search – How to include taxonomy in search?
  72. Custom Post Type meta data getting deleted on bulk editing taxonomies
  73. How to create review point system for CPTs (many-to-many relationship)
  74. After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel
  75. How can I write a function that would update any missing specific post metadata?
  76. SELECT custom post type and its meta in SQL
  77. Custom attachment function not working in v5.4.2?
  78. How to return/export only data showing on screen in custom post type view all screen
  79. Use WP_query to match post types based on custom field values
  80. Custom Function to redirect singular post if specific meta field is empty
  81. Stored meta from attachment, video length?
  82. Saving Child Terms on front end not setting parent
  83. Custom post type: “transition_post_status” action get title and other fields
  84. update a posts of other custom post type
  85. How do I extract the contents of a CPT’s custom field for all posts?
  86. How to get post meta for custom post type and taxonomy
  87. Delete custom post type metadata without deleting the post in admin area
  88. Order by post meta value gets random results
  89. meta query always fails even if data is correct
  90. How to create content automatically when a post is published?
  91. Display a post count from a custom metabox selection
  92. Rich Custom Field for Custom Post type not saving
  93. Add auto increment value to custom meta
  94. Advanced search form with filters for custom taxonomies and custom fields
  95. Post AND page parameter for WP function
  96. How to display Author Profile based on Custom field value
  97. Automatically add custom taxonomy when meta value gets to a set number or beyond
  98. Display a list of posts whose meta field values are equal to the ID of the post being viewed?
  99. Check for custom field value in different post type than current one and do something
  100. I am having a problem with fetching product data in the Gutenberg block editor
Categories custom-post-types Tags add-submenu-page, custom-post-types, post-meta
Route to custom file
Listing all selected terms for custom taxonomies on a post

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