WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Permarad
    Member
    Posted 1 year 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?

    http://wordpress.org/extend/plugins/wp-admin-search-meta/

  2. meloniq
    Member
    Plugin Author

    Posted 1 year ago #

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

  3. bigneno
    Member
    Posted 1 year 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
    Member
    Plugin Author

    Posted 11 months 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
    Member
    Posted 10 months 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
    Member
    Posted 10 months ago #

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

  7. davidsword
    Member
    Posted 10 months ago #

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

    add

    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
    Member
    Posted 4 months ago #

    davidsword's fix works! Thanks.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.