Skip Navigation

[Resolved] Filter by post type

This support ticket is created 6 years, 11 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 11 replies, has 2 voices.

Last updated by Noman 6 years, 10 months ago.

Assisted by: Noman.

Author
Posts
#537755

I am trying to:
Filter by post type. I found this thread:
https://toolset.com/forums/topic/post-type-filter/
I added the custom code and modified it to my view (25).
Then I added the view filter:
[wpml-string context="wpv-views"]Post Type:[/wpml-string] [wpv-control url_param="wpv-post-type" type="select" values=",page,post,sights,food & drinks" display_values="All,Page,Post,sights,food & drinks"]

I visited this URL:
hidden link
I expected to see:
it work

Instead, I got:
It doesn't make any difference. I can't filter on post type.

#537792

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

I have checked the given code but its not working. When I follow the given instructions I can see posts only under “All” and the other post types show no results found. I am going to investigate this further and will update you accordingly.

Thanks

#537811

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Filter by Post type.png

Hello,

I have again checked it and found the problem was in the view’s Query Filter. I have removed the filter and now code is working fine, please match your View options with attached screenshot, I have also added some explanation on the screenshot.

The shortcode you are using is correct already. Please let me know if it resolves the problem.
Thank you

#537860

Still not filtering.

In view id=25 the filter editor I have now:


[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="form-group">
	<label>
[wpml-string context="wpv-views"]Post Type:[/wpml-string]</label>[wpv-control type="select" values=",page,post,sights,food & drinks" display_values="All,Page,Post,sights,food & drinks" url_param="wpv-post-type"]
</div>
[wpv-filter-submit output="bootstrap"]
  [/wpv-filter-controls]
[wpv-filter-end]

#538462

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

To further debug this issue, I need to request temporary access (WP-Admin and FTP Login info) to your staging site.

Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please add the Links to the [View] Edit Screen and [Page] Screen where you have inserted this View.

Looking forward to help you, Thank you

#538517

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

wp-admin.png

I am not able to login and the login page gives error 404. Please see attached screenshot and send us login again.

Your next answer will be private which means only you and I have access to it.

Thank you

#538986

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Yes, it is working now.

Sorry for delay, I am now working on this issue and I will get back to you soon with an update.

Thank you for your patience.

#539043

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Custom function.png

Hello,

I have checked this issue and found two things which I changed to resolve the issue:

- I have changed this line in the shortcode and added correct slug names in this:

 values=",page,post,sight,food-drinks" 

- Add enabled this option in the the Dynamik custom functions and its working now, please see attached for the checkbox option that I have enabled.

You can check now: hidden link

Thank you

#539185

So strange. It works on the replicated site but when I transfer the code it still isn't working. Maybe i didn't transfer the right stuff?

From hidden link I took the View Filter editor:

[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="form-group">
	<label>
[wpml-string context="wpv-views"]Post Type:[/wpml-string]</label>[wpv-control type="select" values=",page,post,sight,food-drinks" display_values="All,Page,Post,sights,food & drinks" url_param="wpv-post-type"]
</div>
[wpv-filter-submit output="bootstrap"]
  [/wpv-filter-controls]
[wpv-filter-end]

On hidden link I checked the slug names of the post types and as expected they are the same.

Then I took the custom code:

/*
https://toolset.com/forums/topic/post-type-filter-select/ */
add_filter( 'wpv_filter_query', 'post_type_filter_func', 10, 3 );
  
function post_type_filter_func( $query_args, $settings, $view_id ) {
    if ( $view_id == 71 && isset($_GET['wpv-post-type'][0]) && !empty($_GET['wpv-post-type'][0]) ) {
        $query_args['post_type'] = $_GET['wpv-post-type'][0];
    }
    return $query_args;
}

As the view id on haarlemtouristinformation.com is 25 I changed it as follows:

/*
https://toolset.com/forums/topic/post-type-filter-select/ */
add_filter( 'wpv_filter_query', 'post_type_filter_func', 10, 3 );
  
function post_type_filter_func( $query_args, $settings, $view_id ) {
    if ( $view_id == 25 && isset($_GET['wpv-post-type'][0]) && !empty($_GET['wpv-post-type'][0]) ) {
        $query_args['post_type'] = $_GET['wpv-post-type'][0];
    }
    return $query_args;
}

So why isn't it working. Should I change something besided the above two alterations?

#539233

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

- Have you enabled this option in the the Dynamik custom functions like in my last reply:
hidden link

- Please make sure there is no filters added in the "Query Filter" section, If you see something there, please remove that.

Code and shortcode looks correct, I don't think there is something else needed unless there is something blocking it from the theme in the live site.

#539526

Hi,
I enabled the option as by your suggestion:
- Have you enabled this option in the the Dynamik custom functions like in my last reply:
hidden link

And now it works. Thanks.

I'm a bit puzzled by it. By enabling this option I understood that it affects the back-end admin section too.

But the filter is for a view which is shown on the front-end. So why does it need to be also back-end enabled?

#539569

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

It's a special filter we are trying to create and we are directly querying post type here which is not normal for a View, it requires deep level query. And I believe that the Dynamik theme’s option is somehow bit too much restrictive for such queries in the code, that’s why we need to enable that and it is safe to enable that.

Thank you

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