WordPress.org

Ready to get started?Download WordPress

Forums

FoxyShop
[resolved] Adding Variation Descriptions to Search (7 posts)

  1. madla
    Member
    Posted 2 years ago #

    I have some text in the variations for some items (name, description field) that I would like to be included in the search.

    My testing indicates that it's not included at all. How would I go about doing that?

    Thanks.

  2. sparkweb
    Member
    Plugin Author

    Posted 2 years ago #

    This isn't handled natively by WP at all, but there's some good tips here: http://wordpress.org/support/topic/include-custom-field-values-in-search?replies=16

    You can edit the search query in the template file: foxyshop-search.php

  3. madla
    Member
    Posted 2 years ago #

    I'm stuck on that one. Based that post, I should be able to add a filter to add more to the search. But I don't know that the right fields are. I'd like to search through category names and descriptions as well as production variation names and descriptions.

    From the post

    function custom_search_where($where) {
        // put the custom fields into an array
        $customs = array('custom_field1', 'custom_field2', 'custom_field3');
    
        foreach($customs as $custom) {
    	$query .= " OR (";
    	$query .= "(m.meta_key = '$custom')";
    	$query .= " AND (m.meta_value  LIKE '{$n}{$term}{$n}')";
            $query .= ")";
        }
    
        $where = " AND ({$query}) AND ($wpdb->posts.post_status = 'publish') ";
        return($where);
    }
    add_filter('posts_where', 'custom_search_where');

    Any help would be appreciated.

  4. sparkweb
    Member
    Plugin Author

    Posted 2 years ago #

    Theoretically this should work, but as I did some test code, I found that it was doing AND instead of OR with traditional meta queries. I haven't been able to figure out how to change that.

    Additionally, all the variation data is stored in separate fields so it would be a large query to search through them all. I'm afraid I don't have a very good solution at this point.

    Sorry....

  5. madla
    Member
    Posted 2 years ago #

    What about the category information? Can I add that to the search?

    Would you mind sharing the test code you mentioned above? If I can see how your accessing the fields perhaps I can figure something out.

  6. sparkweb
    Member
    Plugin Author

    Posted 2 years ago #

    well, I was doing foxyshop-search.php and adding this to the $args:

    $args['meta_query'] = array(
    	array(
    		'key' => '_code',
    		'value' => $search,
    		'compare' => 'LIKE'
    	))

    And that was working, but only if I took out the 's'=>$search bit from the $args. If you look at the query with the blackbox plugin you can see that it's using AND for the meta_query.

    I wonder if it would be better to just do a completely custom query with $wpdb....

  7. sparkweb
    Member
    Plugin Author

    Posted 2 years ago #

    I'd also mention on this one that I have just finished doing some serious upgrades to variation setup for version 3.0. All the variations are now stored in one custom field so it is much more efficient and easier to search variations if you wanted to search that out. If you do want to try this out, send a support request from foxy-shop.com/contact and I'll email you the 3.0 beta.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags