Skip Navigation

[Resolved] Select top-level posts with no parent – filter is not working

This support ticket is created 7 years, 8 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
- 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 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 28 replies, has 2 voices.

Last updated by tomasR-2 7 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#435695

I am trying to: filter CPT with Post parent filter
Exactly as here: https://toolset.com/forums/topic/view-of-pagesposts-within-a-taxonomy-term-and-that-not-have-a-parent-page/

"Hierarchical" in CTP is checked

Result is - without filtering

On the other side - when I filter CTP to get child in parent CTP (something like images in galleries) - this is working perfect.

#435969

Dear tomas,

It is abnormal, I can not duplicate same problem, I suggest you check these:
deactivate other plugins and switch to wordpress default theme, and test again

#435970

Hi Luo,
I have done it - all non-toolset plugins off with delfault theme - result is the same...

#435975

Could you fill below private detail box with login details of your website?
Also point out the problem page URL and view URL, thanks

#435994

Please point out the problem page URL and view URL, thanks

#435996

can you provide private reply please? thank you

#436002

I just enabled the private detail box again. thanks

#436017

Since you provide me the credentials, which username is "Minesh", so I can login into your website with username "Minesh",
And you are using 19 plugins and custom theme, I need your permission to deactivate plugins and switch theme, please back your database first, thanks

#436022

I have done backup as I mention above and I already try to switch all non-tooset plugins and theme but the problem with filtering to show only top level posts with no parent persist.

So you can try it by yourself but for now there is Minesh logged in trying to resolve other problem I have with pagination...

#436027

OK, please update this thread when your website is ready for debug, and I will check it again in tomorrow morning. thanks

#436142

Hi Luo,
site is ready - for now I am continue with creating website - but tomorrow morning (HK time) it will be ready for you with backup.

#436323

Thanks for the details, check it in your website, will feedback if there is anything found

#436328

Your case is different from the thread:
https://toolset.com/forums/topic/view-of-pagesposts-within-a-taxonomy-term-and-that-not-have-a-parent-page/
Above thread is using the Hierarchical custom post type, but you are using parent/child relationship created with Types plugin, see the settings of post type "BAF":
hidden link
in section "Parent Post Types", you have setup post type " Galleries" as the parent post type.

I assume you are going to display those BAF posts which do not have a parent "Galleries" post, it needs custom codes, I added below codes into your theme/functions.php:


add_filter( 'wpv_filter_query', 'no_parent_baf_func', 10, 3 );

function no_parent_baf_func( $query_args, $view_settings, $view_id ) {
	if($view_id = 403) {
		$query_args['meta_query'][] = array(
			'key'     => '_wpcf_belongs_galleries_id',
			'compare' => 'NOT EXISTS',
		);
	}
	return $query_args;
}

More help:
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/

#436363

Thanks Luo - it is now working this way now

but it stops working other way - now the filter to show child posts (BAF) in parents posts (Gallery) is not working...

I am little bit confused about what is different in Parent/Child and hierarchical if in hierarchical you must use Parent/Child relationship...

and one more question:
how to set up the code you add to functions.php to all views?

#436379

Q1) In other cases, for example:
now the filter to show child posts (BAF) in parents posts (Gallery) is not working
You will need to create another view for it.

Q2) I am little bit confused about what is different in Parent/Child and hierarchical if in hierarchical you must use Parent/Child relationship...
They are different, the hierarchical post type is a feature of wordpress, we use it in only one post type, for example:
Custom post type A
--Parent post 1
---- Child post 2
------ Grandchild post 3
see document:
https://codex.wordpress.org/Function_Reference/register_post_type#hierarchical
hierarchical
(boolean) (optional) Whether the post type is hierarchical (e.g. page). Allows Parent to be specified. The 'supports' parameter should contain 'page-attributes' to show the parent select box on the editor page.

The parent/child relationship pot types created with Type plugin, which is take effect on two post type, one is parent post type, the another is child post type, for example:
Post A (Parent post type A)
-- Child post B1 (Child post type B)
-- Child post B2 (Child post type B)
-- Child post B3 (Child post type B)
https://toolset.com/documentation/user-guides/creating-post-type-relationships/

Q3) how to set up the code you add to functions.php to all views?
The codes I provided is only an example, you can customize it by yourself, for example, you can apply it to two or more views:
Replace this line from:

if($view_id = 403) {

To:

if(in_array($view_id, array(123, 456, 789))) {

Please replace those number 123, 456 with the specific Views ID, when you edit a view, you can get the Views's ID in the browser URL.
And it is not recommended to apply the same filters to all of your Views, it will conduct some unexpected result.

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