Crocoblock / suggestions

The suggestions for CrocoBlock project
195 stars 78 forks source link

JetSmartFilters: Ability to search both Default WordPress Search fields and 1 or More Custom Fields at the same time #4170

Open eSilverStrike opened 3 years ago

eSilverStrike commented 3 years ago

To expand on feature request #2409 which has now been added to JetSmartFilters. You can now include multiple custom fields to search for a single text box.

Unfortunately there appears to be no way to include "Default WordPress Search" AND a list of custom fields.

Please add the ability to have a single text box that will search the title, editor, and any custom field of a custom post type.

When adding a Filter Type "Search", a new item should be added to the select box for "Search by" called "Both". When "Both" is selected "Default WordPress search" and "By Custom Field (from Query Variable)" will both be used in the search. The "Query Variable" field will be enabled allowing multiple field keys separate them with commas to be added.

Another important option as well is the ability to include taxonomies in the search. For example if the post belongs to the "News" category and a visitor searches for "news" then any post in the news category should come up along with any other matches from the fields you have it selected to search on.

blb48 commented 2 years ago

I'm in a similar situation, would love if a single Search Filter could target both Titles and custom fields.

torpedovandals commented 2 years ago

I agree.

keet789 commented 2 years ago

Totally agree! And it would be nice to include the post author in the search as well. Default WP search couldn't search for post author, and setting the author as a meta field is so unnecessary.

Khairulbrri commented 1 year ago

I agree.

xokko commented 7 months ago

How is this still not possible?

Avaroth commented 6 months ago

Hey folks! I might have a solution for you!

I've been working on a solution for one of my projects. It works pretty good, although it's a dirty hack.

Whenever my post is saved, I also update a meta field with a given name. Since I now have a meta field, I can just include this meta field name in the search filter, and it also looks up the search in this field, which is, the title of the post :)

add_action( 'save_post_{ENTER_YOUR_POST_TYPE_HERE}', 'add_meta_title', 10, 3 );

function add_meta_title( $post_id, $post, $update ) {
    update_post_meta( $post_id, '{WHATEVER_YOU_WANT_TO_CALL_YOUR_TITLE_META_FIELD}', get_the_title($post_id) );
}

It should be safe to use this, since the title is already sanitized when being saved. If you have any doubts, use the sanitize_text_field() function to ensure it's clean.

xokko commented 6 months ago

I use the excerpt field (which I don't use for excerpts), where I always save the title and other custom fields concatenated. It works well.

antoinelbch commented 1 week ago

+1