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. SQL query based on two different custom field values
  26. Using meta query (‘meta_query’) with a search query (‘s’)
  27. Can I exclude a post by meta key using pre_get_posts function?
  28. Advanced search form with filters for custom taxonomies and custom fields
  29. Custom post meta field effect on the performance on the post
  30. How to get custom post meta using REST API
  31. Difference between meta keys with _ and without _ [duplicate]
  32. Orderby meta_value only returns posts that have existing meta_key
  33. What is the index [0] for on post meta fields?
  34. What is “meta_input” parameter in wp_insert_post() used for?
  35. How to enable revisions for post meta data?
  36. The “_encloseme” Meta-Key Conundrum
  37. Best way to programmatically remove a category/term from a post
  38. SQL Query to copy value of a meta_key into another meta_key
  39. How to correctly call custom field dates into a posts_where filter using SQL statements
  40. Using get_post_meta with new_to_publish
  41. Including custom fields in search?
  42. Admin Area Custom Type Search By Meta Fields Without Title & Content
  43. SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
  44. How can I make wp-pagenavi work on a custom query built upon a form submission? [closed]
  45. Custom field metabox not showing in back-end
  46. How do I Paginate Search Results for Custom Post Types?
  47. Meta Query with AND & OR?
  48. So much data in postmeta
  49. Custom search: by post data and post metadata?
  50. Can I count the number of users matching a value in a multiple value key?
  51. Need small coding with Custom Fields Search
  52. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  53. How to hide meta box values from custom fields list?
  54. Auto sort the wp-admin post list by a meta key
  55. Search custom post type by meta data
  56. get_post_meta() unserialize issue – returns boolean(false)
  57. What is the advantage of the wp_options design pattern?
  58. Search ONLY by meta key / meta values
  59. Storing meta fields multiple times OR once with multi dimensional array?
  60. Allow user to create instances of custom field
  61. display specific custom fields
  62. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  63. Filter results with custom field values and dropdown
  64. Meta keywords and descriptions plugin for manually editing meta for each page/post
  65. Add custom field (value) to search result (without plugin)
  66. How to display multiple Post meta_key/meta_values by SQL query
  67. passing argument to get_template_part() or a better way to code
  68. Is it possible to store arrays in a custom field?
  69. Get updated meta data after save_post hook
  70. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  71. Save HTML formatted data to post meta using add_post_meta()
  72. Search everything (posts, pages, tags, cpt, meta)
  73. importing data from non-wordpress mysql db
  74. Is there a way to do multiple ordering on a multiple meta_query?
  75. searching in custom meta field
  76. Bulk move (or copy) from a custom field to the post content?
  77. Create meta boxes that don’t show in custom fields
  78. Transients vs CRON +Custom Fields: Caching Data Per Post
  79. Unable to save datetime custom meta field using update_post_meta() function
  80. post meta data clearing on autosave
  81. WordPress Search Custom Meta Field Only
  82. Custom Fields Bulk Edit
  83. Create custom field on post draft or publish?
  84. Display info from custom fields in all images’ HTML
  85. Ordering posts by anniversary using only day and month
  86. Exclude custom post type from search by custom field value?
  87. get_post_meta fields don’t show up on posts page
  88. Update meta values with AJAX
  89. How to break meta values into different items and avoid duplicates?
  90. copy attachments to another post type and change attachment url
  91. Cannot edit post meta fields with rest API
  92. ajax delete value from custom field array
  93. Save attachment custom fields on front end
  94. How to use pagination with get_post_meta
  95. Copying Custom Meta Values from existing post to a duplicate post
  96. Add a post meta key and value only if it does not exist on the post
  97. Move value of one custom field to another
  98. Order posts according to user defined order for meta values?
  99. Displaying posts with only upcoming dates according their custom field date value
  100. Custom fields to save multiple values
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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