Navigation überspringen

[Gelöst] View returning all entries from wp_toolset_connected_elements

This support ticket is created vor 1 year, 9 months. 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Zeitzone des Unterstützers: Asia/Karachi (GMT+05:00)

Dieses Thema enthält 1 reply, hat 2 Stimmen.

Zuletzt aktualisiert von Waqar vor 1 year, 9 months.

Assistiert von: Waqar.

Author
Artikel
#2689074
Screenshot 2024-03-21 at 9.33.28 a.m..png

I have a view that displays a repeatable field group. It select posts in Any relationship that are related to the Post with ID set by a shortcode attribute.

If that Post ID doesn't exist, the view should display a "No results" message. Instead, it's returning all the posts that are on the wp_toolset_connected_elements table (even if they are not related at all).

#2689152

Hi,

Thank you for contacting us and I'd be happy to assist.

Your observation is correct and this is the default behaviour. But, the 'wpv_filter_query' can be used to change that:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query


add_filter( 'wpv_filter_query', 'filter_posts_specificmix_check', 1000 , 3 );
function filter_posts_specificmix_check( $query_args, $view_settings ) {
	// check if specific view
	if ( !is_admin() && ( isset($view_settings['view_id']) && $view_settings['view_id'] == 12345) ) {
		global $WP_Views;
		$attributes = $WP_Views->view_shortcode_attributes;
		// if 'specificmix' attribute value
		if ($attributes[0]['specificmix'] <= 0 ) {
			$query_args['post_type'] = 'xyz';
		}

	}
	return $query_args;
}

Note: You'll replace '12345' with the actual ID of your target view.

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

This function will check if a specific view is being viewed and if 'specificmix' attribute value is less than or equal to '0', will change the post type to a fake post type 'xyz', which will show no results.

regards,
Waqar