WordPress.org

Ready to get started?Download WordPress

Forums

Simple Fields
Slug names as meta keys? (1 post)

  1. _duncanhall
    Member
    Posted 9 months ago #

    First, thanks for the great plugin, it's solved a lot of problems for me already.

    I'm trying to include custom (simple) fields as searchable terms.

    I have a hook for the posts_where search filter, and I'm trying to use the postmeta.meta_key to match against a custom field.

    function custom_search_where($where)
    {
    	if (is_search())
    	{
    	 	global $wpdb;
    		$where .= " OR (($wpdb->postmeta.meta_key = 'custom_field_slug') AND ($wpdb->postmeta.meta_value LIKE 'some_value'))";
    	}
    
        return($where);
    }
    
    add_filter('posts_where', 'custom_search_where');

    I'd assumed the slug I entered when creating the simple field would be used as the meta_key, but it doesn't seem to be the case.

    From what I can tell, the actual meta keys assigned when creating a simple field, are along the lines of:

    _simple_fields_fieldGroupID_2_fieldID_added_numInSet_5

    Can you confirm if this is the case? If so, is there any way for me to get these values, referenced by slug name?

    Alternatively, is there another way of including simple fields in search queries?

    I've tried the Search Simple Fields plugin but it doesn't seem to work.

    Thanks.

    http://wordpress.org/plugins/simple-fields/

Reply

You must log in to post.

About this Plugin

About this Topic