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

searching by keywords in post’s metas or pagination links problem

Okay. I solved it by myself. i dunno what’s wrong, but it looks like using first case – just doesn’t work. using second case – is a bad idea.

so i began to work with sql and posts_where commands.

first: instead of $wp_query->query_vars['s'] i started to use get_search_query()

second: looks like when sql tries to compare meta_value with value, it asks for %. yes, so in sql code you should write something like:

wp_postmeta.meta_key LIKE \'_entitle\' AND wp_postmeta.meta_value LIKE \'%' . get_search_query() . '%\'

third: because you are using wp_postmeta, you must join its posts ids with ids from wp_posts:

function dasdasd( $join, $query ) {
    global $wpdb;

    if ( is_search() ) {    
        $join = 'INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )';
    }

    return $join;
}
add_filter('posts_join', 'dasdasd', 10, 2 );

and fourth: i dunno why but you must add groupby code:

add_filter( 'posts_groupby', 'adadad', 10, 2 );

function adadad( $groupby, $query ){
    $groupby = 'wp_posts.ID';

    return $groupby;
}

i would like to know what’s wrong with fourth step and why groupby’s existing is so important for search query. thank you.

Related Posts:

  1. Add custom fields to search
  2. How to rename a custom field?
  3. Up/Down voting system for WordPress
  4. sort search results by custom fields using dropdown
  5. How can I sort homepage by a meta value?
  6. How do I use wp_query for WordPress search?
  7. Custom Field Create Bulk via SQL Query
  8. filtering custom post types via meta data drop down
  9. How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?
  10. Custom WP_Query for WordPress Search Results with meta_query
  11. Limits, not all post are showen when querying for posts by view count
  12. How can you include custom post meta in search without calling each key?
  13. Custom search SQL Query to add custom field in result
  14. How to exclude custom fields from search queries?
  15. Custom Query: query by post custom meta data
  16. Searching with Multiple (Parallel) Criteria on Custom Fields?
  17. Search & column order by meta value in admin
  18. SQL query to change the value of a Custom Field
  19. Search one custom field?
  20. Create custom query for search?
  21. Query postmeta values, and return multiple post_titles for common meta value
  22. query specific posts according their custom fields, using sql SELECT
  23. How to display search query as formatted text?
  24. Search for meta_query does not return any result if combined with title
  25. Using meta query (‘meta_query’) with a search query (‘s’)
  26. Advanced search form with filters for custom taxonomies and custom fields
  27. Custom post meta field effect on the performance on the post
  28. Difference between meta keys with _ and without _ [duplicate]
  29. Orderby meta_value only returns posts that have existing meta_key
  30. How to enable revisions for post meta data?
  31. Including custom fields in search?
  32. How do I Paginate Search Results for Custom Post Types?
  33. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  34. Storing meta fields multiple times OR once with multi dimensional array?
  35. passing argument to get_template_part() or a better way to code
  36. Is it possible to store arrays in a custom field?
  37. importing data from non-wordpress mysql db
  38. Is there a way to do multiple ordering on a multiple meta_query?
  39. searching in custom meta field
  40. Bulk move (or copy) from a custom field to the post content?
  41. Create meta boxes that don’t show in custom fields
  42. Custom Fields Bulk Edit
  43. Copying Custom Meta Values from existing post to a duplicate post
  44. Move value of one custom field to another
  45. Order posts according to user defined order for meta values?
  46. Displaying posts with only upcoming dates according their custom field date value
  47. Get a post_id where meta_value equals something in a serialized meta_value field
  48. How to save a ToggleControl value in a meta field?
  49. How do I query for a post by custom field?
  50. Including Database Generated Pages in Site Search [closed]
  51. Adding Custom Fields to Search
  52. Get specific custom field keys from a post and put into an array
  53. Loop to display random posts only if a custom field matches category
  54. How make a custom search on backend in WordPress without plugin?
  55. Create Multiple File Upload Metabox in WordPress
  56. If meta key exists in get posts function otherwise create it
  57. How do I Implement Atomic Update of Post Metadata?
  58. Why is my Custom Meta Box Field Inputs NOT saving?
  59. Get registered custom fields or post meta even if empty
  60. Display Custom Meta Box Field Only If Value is Present
  61. Get post ids sorted by meta_key
  62. Unable to get specific value from post meta
  63. pre_get_posts : only get posts by wp_usermeta value
  64. Custom meta is not being saved
  65. Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
  66. IF Custom field value equals ZERO
  67. How to query two meta fields and display results between them
  68. Let’s Create Custom Field Template Documentation
  69. Looping inside block return
  70. WordPress creates new lines in postmeta table on post update
  71. User customising position of WordPress Featured Image
  72. Meta box values are displayed on Custom Fields list. Is it possible to hide them?
  73. Best way to achieve multiple links in a post title
  74. Show array of meta_value in Edit Post Coloum
  75. Best way to sort estates and query them (for rent? yes/no. contains office space? yes/no)?
  76. Get array of posts based on custom field values
  77. Get author total post votes from post meta
  78. custom filed from post in the side bar
  79. Build A Custom SQL Query for WordPress Search
  80. How to display custom fields in hestia theme
  81. How to speed up post list slowed by update_meta_cache()?
  82. WordPress Blocks, setAttributes not saving
  83. search based on custom field
  84. Custom meta POST request fired twice when updating a post in Gutenberg
  85. Update custom field on page specific to logged in user
  86. Save, update, get and sanitize post meta as HTML not plain
  87. Create Meta boxes dynamically
  88. Saved Post Meta Array Returns as String
  89. Problem saving meta data
  90. Admin – Search Events by a custom field
  91. Check if value exists before saving
  92. Get meta value when the page is a blog archive
  93. Custom Search Query – include only custom fields and title
  94. wp_postmeta are updated for only one page
  95. Meta_query not filtering posts
  96. How to add a prefix to existing custom fields over MYSQL query?
  97. Complex WP_Query Using Post Date And Post Meta
  98. Make Custom Fields Public in JSON – API
  99. Order by a meta field in query loop
  100. WP Query Args – search by meta_key or title
Categories custom-field Tags custom-field, post-meta, query, search, sql
Group Custom Posts Types in a Relation field of ACF
How to get all the users list after you performed the hook "pre_get_users"?

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