Problem:
The issue here is that the user wanted to filter their current view by the custom field on the current page.
Solution:
In this case the user was using the Classic Editor for Blocks to create their view so they are able to use this method below.
What you need to do is to add a query filter to your view and then set the query filter to get the value from a shortcode attribute.
Then you will be able to filter the view by passing the shortcode directly into the view like this.
[wpv-view name='my-view' param="[types field='my-field'][/types]"]
Where my-view is the slug of your view "param" is the shortcode parameter you've set in the filter and "my-field" is the slug of the field.
If you are using the Block view then this can be done by using the Hook below.
add_filter( 'wpv_filter_query', 'filter_by_post_customfield',99,3 );
function filter_by_post_customfield( $query_args,$view_settings,$view_id ) {
if ( $view_id == 4187) {
$post_id = get_the_ID();
$meta_val = get_post_meta($post_id, 'wpcf-parent-model-name-custom-field' );
$query_args['meta_query']= array(
array(
'key' => 'wpcf-parent-model-name-custom-field',
'value' => $meta_val[0],
'compare' => '=',
),
);
}
return $query_args;
}
To use the Hook add it to your Toolset Custom code section in Toolset -> Settings -> Custom Code and add it. Ensure that it has been activated.
Now what you need to do is to change the 4187 to the ID of your view and change "wpcf-parent-model-name-custom-field" to the slug of the custom field that you want to get the value for on the current page keeping the wpcf- prefix.
Next replace the second instance of wpcf-parent-model-name-custom-field to the field slug that you want to check for on the post type that the view is listing. In this user's case both fields were on the post being queried.