Skip Navigation

[Resolved] Question about query filters on Views

This thread is resolved. Here is a description of the problem and solution.

Problem:

Add a specific post to Views query:
At this point I'm expecting that a custom query is the only way to get what I want. In SQL terms, I would issue a SELECT statement whose where clause specifies "person_type='alumni' or post_id=XXXX."

Solution:

There is a workaround without any custom codes, you just need two post views:

1) First view query the post, filter by: Include only posts with the following IDs: 3499

2) Second view query all alumni posts

Then display above two views one after another.

Relevant Documentation:

This support ticket is created 6 years, 6 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 6 replies, has 2 voices.

Last updated by josephQ 6 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#923011
filter that failed - no items found.png
current alumni filter.png

Hi there,

I've got a question about query filters on Views. I have a custom post type named Person. The CPT has a field named Person Type, which has 4 possible values: Student, Alumni, Faculty, and Guest. I've created a view to show just alumni with no problem. That page can be seen here:

hidden link

Here's a link to the View responsible for it:

hidden link

And I've attached a screenshot of the query filter (current alumni filter.png). ("Hide" is a field whose value is "1" to ignore the person or "0" to not ignore the person, in case we want to hide people on the above webpage.)

One of the faculty, however, is an alumni. Can I create a query filter which says "get all alumni who are not hidden and also get the faculty person with a post ID of XXXX"?

Thanks!

#923308

Hello,

For the question:
Can I create a query filter which says "get all alumni who are not hidden and also get the faculty person with a post ID of XXXX"?

1) alumni who are not hidden
Select items with field:
Hide is a number equal to 1

2) the faculty person
Person Type is a string equal to faculty

3) Post ID filter
Include only posts with the following IDs: 3499

See it in your website:
hidden link

And the result:
hidden link

#923834
Screen Shot 2018-07-11 at 23.13.57.png

Luo,

Thanks for your reply. The test page that you set up doesn't seem to illustrate the desired result: I was expecting to see a list of the 106 alumni *and* the record for the one faculty member, Martha (ideally, alphabetically mixed into the listing of the alumni and not tacked onto the beginning or end of the list). Instead the webpage just showed a link to Martha and a couple of other strange pieces of information.

Am I missing something?

#923860
filter.PNG

OK, let's handle the question one by one,

Please check your original post:
https://toolset.com/forums/topic/question-about-query-filters-on-views/#post-923011
"get all alumni who are not hidden and also get the faculty person with a post ID of XXXX"?

According to your description, I have setup a view in your website:
hidden link
See section "Query Filter", with three filters:
1) Select items with field: Hide is a string equal to 0
It is for your text: "who are not hidden"

2) Person Type is a string equal to faculty
It is for your text: "get the faculty person"

3) Include only posts with the following IDs: 3499
It is for your text: with a post ID of XXXX

See screenshot: filter.PNG, it is only an example for setup filters in the view.

Does these filters works as what you mentioned in original post? can you confirm it? thanks

#924034

Luo,

Thanks for your reply. There's an issue with your description of the filter:

> 1) Select items with field: Hide is a string equal to 0
> It is for your text: "who are not hidden"

YES!

2) Person Type is a string equal to faculty
It is for your text: "get the faculty person"

NO! I want to get "alumni."

> 3) Include only posts with the following IDs: 3499
> It is for your text: with a post ID of XXXX

YES!

So, again, I want to get a list of all *alumni* _and_ one post ID which is _not_ an alumni (the one faculty member).

Does that make sense? Is that possible? At this point I'm expecting that a custom query is the only way to get what I want. In SQL terms, I would issue a SELECT statement whose where clause specifies "person_type='alumni' or post_id=XXXX."

#924042

Thanks for the details, you are right, there isn't such kind of feature within single post view, if you are going to use custom SQL query codes, that is out the range of Toolset support. Here are some similar ticket for your reference:

https://stackoverflow.com/questions/26465954/add-some-posts-to-top-using-wp-query
https://wordpress.stackexchange.com/questions/206235/add-few-specific-post-ids-to-wp-query

There is a workaround without any custom codes, you just need two post views:
1) First view query the post, filter by: Include only posts with the following IDs: 3499
2) Second view query all alumni posts

Then display above two views one after another.

#924146

Luo,

Makes sense. Thanks again for your help. I appreciate it!