Skip Navigation

[Resolved] querying multiple fields using a toolset filter

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 3 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#1787917

hello, i have a filterable archive page here: hidden link

i have a search field called "Ordering Part Number"

I want this field to filter such that the filter checks to see if the string entered is in any of these custom fields:
Ordering Part Number
Catalog Part number
Old Catalog Part number

to do so, i'm using this: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

here is the code i've made: hidden link

function tb_search_multi_fields( $query_args, $view_settings, $views_id ) {
// !isset($_GET['wpv_filter_submit'])
// $_GET['action'] == "wpv_get_archive_query_results" &&
// 9701773300
if ( $_GET['action'] == "wpv_get_archive_query_results" ) { // if it is specific view and by default
$value = $_GET["search"]["dps_general"][4]["value"];

$query_args['meta_query'][] = array(
'relation' => 'OR',
array(
'key' => 'wpcf-ordering-part-number',
'value' => $value,
'compare' => 'LIKE'
),
array(
'key' => 'wpcf-catalog-part-number',
'value' => $value,
'compare' => 'LIKE'
),
array(
'key' => 'wpcf-old-catalog-part-number',
'value' => $value,
'compare' => 'LIKE'
)

);

}

return $query_args;
}
add_filter( 'wpv_filter_query', 'tb_search_multi_fields', 101, 3 );

I think I am doing this correctly, but it always shows no results. Could you help explain why this is happening?

I think you will need to log in. to do so simple CLICK HERE to be logged in automatically: hidden link

edit: to further clarify, if i search for "9701773300" this result should appear: hidden link

#1788693

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As you are using the archive, you will require to use the pre_get_posts:

Can you please try to use that. For example:

add_action( 'pre_get_posts', 'func_archive_for_post_type' );
function func_archive_for_post_type( $query ) {

if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'air-filter' ) ) {
                               /// add your code here
		 
	}

}

Please try to adjust the code you added within the pre_get_posts action and check if that help you to resolve your issue.

More info:
=> https://developer.wordpress.org/reference/hooks/pre_get_posts/

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.