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!
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
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?
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
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."
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.
Luo,
Makes sense. Thanks again for your help. I appreciate it!