Skip Navigation

[Closed] Filter by Post Types and/or Post ID

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 8 replies, has 1 voice.

Last updated by Minesh 5 months, 4 weeks ago.

Assisted by: Minesh.

Author
Posts
#2795312

Tell us what you are trying to do?

I would need filter that returns all posts of the type communities and hub as well as the pages with ID 20307 and 21710

Is there any documentation that you are following?

Found nothing.

#2795373

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Assuming that you are using view block, with the view block on right sidebar you will see a "Content Selection" tab where you can enable the option "Allow multiple post type" that will allow you to select multiple post types.

Please check the following screenshot:
- https://toolset.com/wp-content/uploads/2023/03/2568769-multipleposttypes.png

From where you should try to select communities and hub and page post types.

Then try to add the following view's filter hook to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_filter( 'wpv_filter_query', 'func_filter_parent_view_by_child_post_fields', 10, 3 );
function func_filter_parent_view_by_child_post_fields( $query_args, $view_settings, $view_id ) {
 
  if( $view_id ==99999  ) {
     
	/// please chane post type slug and page ids to include where applicable
    $comunity_post_type_slug = 'community';
	$hub_post_type_slug = 'hub';
	$target_page_ids_to_inclucde = array(20307,21710);
	
	$args = array(	'post_type' => array($comunity_post_type_slug,$hub_post_type_slug),
					'fields' => 'ids',
					'post_status' => 'publish',
					'posts_per_page' => -1);
	$community_hub_ids= get_posts($args);
    
	$final_result =   array_merge($community_hub_ids,$target_page_ids_to_inclucde);
	
     
   // passing found parent post ids
   $query_args['post__in'] = $final_result;     
     
  }
   
 return $query_args;
}

Where:
- Replace 9999 with your original view ID and adjust the code accordingly

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

I hope above solution will help you to resolve your issue.

#2795377

Hi Minesh,

works like a charm. Except that now my filters are empty.

hidden link

Michael

#2795378

Minesh
Supporter

Languages: English (English )

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

The custom search filters will display the values for the dropdown options where results are available.

Normally - when you use custom search it should be attached to only one post type as you can add custom search filters for custom fields/taxonomies etc..etc.. belongs to that post type.

I would like to know the filters Countries and Regions are taxonomy or custom field filters and it belongs to what post type?

#2795379

Countries and Regions are both taxonomy and are available with all three post types in this view: Page,Community, Hub

#2795380

Just so you now my goal:

I want to show all Hubs and Communities that works just fine.

And in addition I would like to see in that list the links to the two pages 20307,21710.

Maybe there is another way.

#2795381

Minesh
Supporter

Languages: English (English )

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

What if you disable the the code I shared for a moment.

Then,
- Create a view 1 and set that view to query post type Hubs and Communities.
- create a view 2 and set this view to query post type page and add query filter for post ID and include your post IDs:
==> https://toolset.com/course-lesson/filtering-custom-lists-of-posts/#filtering-options

And then add view 1 and just below that add view 2.

Does that helps?

#2795382

Not really :/

I want them to be alphabetically sorted all together.

#2795395

Minesh
Supporter

Languages: English (English )

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

The thing is that view offers the filter options by defualt for the actual result available.

I'm not sure if you are using block view or classic view. Can you please send me admin access details and problem URL and let me check what we can do in this case.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

The topic ‘[Closed] Filter by Post Types and/or Post ID’ is closed to new replies.