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

Exclude from the query posts with meta_key and meta_value

I think you’ll need to add a posts_join filter, to join the posts and postmeta tables.

This link should be helpful: http://codex.wordpress.org/Custom_Queries, in particular this piece of example code:

add_filter('posts_join', 'geotag_search_join' );
add_filter('posts_where', 'geotag_search_where' );

function geotag_search_join( $join )
{
  global $geotag_table, $wpdb;

  if( is_search() ) {
    $join .= " LEFT JOIN $geotag_table ON " . 
       $wpdb->posts . ".ID = " . $geotag_table . 
       ".geotag_post_id ";
  }

  return $join;
}

function geotag_search_where( $where )
{
  if( is_search() ) {
    $where = preg_replace(
       "/\(\s*post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
       "(post_title LIKE $1) OR (geotag_city LIKE $1) OR (geotag_state LIKE $1) OR (geotag_country LIKE $1)", $where );
   }

  return $where;
}

Related Posts:

  1. Remove post from latest posts after a month only with certain tag
  2. Add options to featured image
  3. mysql custom wp query
  4. Change meta tags programatically
  5. Use a function to update post meta based on other post meta
  6. update_post_meta for custom field not working upon form submission
  7. WordPress – thumbnail image from youtube (function and loop)
  8. Assign category using custom field?
  9. Convert User ID’s to User Names in a single.php file
  10. Can’t check if a post has thumbnail adding filter to get_post_metadata()
  11. Move Post to different category if post_meta field is 0 or is 2 days old?
  12. What WordPress function to use to get meta value by using meta keys?
  13. show first 3 thumbnails of posts in different sizes [closed]
  14. Default Custom Field Value Automatically Update
  15. Post meta not updating
  16. Function to update post_meta based on existing post_meta
  17. How to obtain the recent posts without their content in an efficient way?
  18. Prevent custom field from being updated after first publish
  19. Get array of metakey in all posts
  20. User function to return multiple get_post_meta()
  21. What are the meta fields for an attachment?
  22. Using functions.php to include code that’s processed inline
  23. Getting images from media library and get_the_date() not working
  24. How to avoid saving empty data to sql while using add_meta_box
  25. How to change text color depending on the number value (Using javascript)
  26. How to add custom metakey to shop_order page’s searching function?
  27. Update wp_postmeta table based on 2 keys
  28. blank page with wp_get_attachment
  29. Reference multiple style sheets, clearing styles for permalink page, custom fields for css
  30. How To Display Author Popup on Entry Meta (Genesis Framework)?
  31. Creating a “Related Meta” type field?
  32. save_post doesn’t correctly process function call with php class
  33. Pagination not working on my archive page for a custom post type
  34. Return ACF Field value function
  35. update_post_meta not working in function
  36. How To Get WordPress Categories Last Update Date?
  37. How to add a meta information to the URL?
  38. Automatically add custom fields (post_meta) to all published posts, hourly, via wp_cron?
  39. update_post_meta after form is submited
  40. Add custom fields after post/page title
  41. Display post_meta-by_key on product catalogue
  42. Integrating custom API for post content into Admin interface & Public Website [closed]
  43. How to save custom made object in an array in a post meta field
  44. Adding and updating repeating custom field meta data
  45. Missing feature image link function
  46. What’s the difference between home_url() and site_url()
  47. Remove “Category:”, “Tag:”, “Author:” from the_archive_title
  48. get_template_directory_uri pointing to parent theme not child theme
  49. How to customize the_archive_title()?
  50. remove empty paragraphs from the_content?
  51. what is the correct way to compare dates in a WP query_posts meta_query
  52. What is the “with_front” rewrite key?
  53. Why use if function_exists?
  54. How to override parent functions in child themes?
  55. wp_enqueue_script was called incorrectly
  56. Add multiple custom fields to the general settings page
  57. Ajax call always returns 0
  58. 400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook
  59. How long does a deprecated function live in core?
  60. Solution to render Shortcodes in Admin Editor
  61. How to add a data attribute to a WordPress menu item
  62. What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
  63. remove_action on after_setup_theme not working from child theme
  64. plugins_url vs plugin_dir_url
  65. Remove type attribute from script and style tags added by WordPress
  66. How to run a function every 5 minutes?
  67. Best way of passing PHP variable between partials?
  68. Upload Multiple Files With media_handle_upload
  69. How to display custom field in woocommerce orders in admin panel?
  70. Adding fields to the “Add New User” screen in the dashboard
  71. Issues with title-tag and document_title_parts
  72. How do I get the current edit page ID in the admin?
  73. How to check if a user exists by a given id
  74. Why isn’t is_page working when I put it in the functions.php file?
  75. Add tags to the section via functions.php
  76. Add image size if page template
  77. How to create a custom order status in woocommerce!
  78. Remove Actions/Filters added via Anonymous Functions
  79. Adding a second email address to a completed order in WooCommerce [closed]
  80. How to load parent_theme functions.php before child_theme?
  81. How to load scripts/styles specific for a page
  82. Programatically add options to “add new” custom field dropdown
  83. Is there any global functions.php file which works for any theme?
  84. Excluding iPad from wp_is_mobile
  85. When should you, and when should you not, use wp_list_pluck()?
  86. Get the ID of the page a menu item links to?
  87. Add container to nav_menu sub menu
  88. Difference between the_permalink() and get_permalink() function
  89. What’s the difference between WordPress random_int() and PHP built-in function random_int()?
  90. Child theme – Overriding ‘require_once’ in functions.php
  91. Order by meta value or date?
  92. Link to user’s profile settings page?
  93. WordPress Enqueue for homepage only, functions.php, wp-framework
  94. get php variable from functions php and echo it in theme template files [closed]
  95. Get menu object from theme_location
  96. Is it ok to use a function to output the text domain name in a wordpress theme
  97. Displaying the number of updates available in the Admin area
  98. Trying to use add_action and do_action with parameters
  99. Filtering posts by post meta data
  100. Use AJAX in shortcode
Categories functions Tags functions, post-meta, query-posts
How to apply next/previous classes to LIs for pagination links?
What PNG Fix script do you recommend for IE6?

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