WP-Admin Search Post Meta
[resolved] Result displayed multiple times. (8 posts)

  1. Permarad
    Posted 2 years ago #

    The plugin does include meta fields in the search now but in the search results I am getting individual posts repeated up to 35 times on the results page.

    There must be no checks to prevent the post being displayed more than once?


  2. meloniq
    Plugin Author

    Posted 2 years ago #

    Do you use some other plugins on your site? If so, which? Maybe it got into conflict with other plugin.

  3. bigneno
    Posted 2 years ago #

    Permarad is right - there is a bug.
    This happens when you have many postmetas attached to one post (even hidden with keys starting with "_") . This plugin uses only one LEFT JOIN.

    Each postmeta key-value pair has it's own row in postmeta table, so this plugin should generate a JOIN query for each pair, not just one.
    For example:

    $join .= "LEFT JOIN (SELECT post_id,meta_value FROM $wpdb->postmeta WHERE meta_key='_firstkey') meta1 ON $wpdb->posts.ID = meta1.post_id
    LEFT JOIN (SELECT post_id,meta_value FROM $wpdb->postmeta WHERE meta_key='_secondkey') meta2 ON $wpdb->posts.ID = meta2.post_id ...
    $where .= " OR ( meta_value LIKE '%{$wp->query_vars['s']}%' ) ";

    You should modify this plugin to use ONLY ONE user-defined postmeta key or build a large JOIN query for all existing postmeta keys.

    Hope this was helpful.

  4. meloniq
    Plugin Author

    Posted 2 years ago #

    Multiple JOIN's are required only to query with AND, and not an OR

    For any sort of improvements (and even more rich description of plugin), PR welcome: https://github.com/meloniq/wp-admin-search-meta

  5. theWPcoach
    Posted 2 years ago #

    Is the way to fix this to use the code above? I only need to add the ability to search 1 item in the meta data. Thanks and let me know.

  6. Robert
    Posted 2 years ago #

    I also have this bug, a fix would be great :-)

  7. davidsword
    Posted 2 years ago #

    I was getting the same error. I was able to fix it by adding a DISTINCT filter


    add_filter('posts_distinct', array( __CLASS__, 'search_distinct') );

    to static function add()

    then the search_distinct() function to the class:

    static function search_distinct() {
    		return "DISTINCT";


    ALSO for anyone looking to have meta search on the front end, I commented out the following:

    		if ( ! is_admin() )
    			return false;
    		if ( 'edit.php' != $pagenow )
    			return false;
  8. KASKA
    Posted 1 year ago #

    davidsword's fix works! Thanks.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP-Admin Search Post Meta
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.