Hi Toolset,
I would like to query posts in my view by url parameters, but not with the ID but the a text.
I created a view with 3 posts (ads) here: hidden link
As you can see it filters the posts but not the 3 ads at the top. When i go to here hidden link it works but doesn't show posts anymore (only ads).
Is it possible to filter a view by url parameter texts? Is it possible to refine the ads when a visitor clicks more filters?
Thanks,
Menno
Dear Menno,
I assume we are talking about the same question as another thread:
https://toolset.com/forums/topic/query-view-based-on-url-parameters/
Please check the answer in above thread, and close this one.
Yes it's the same question.
So, which thread do you want me to answer? this new ticket or old ticket?
Here are what I found in your website:
1) The URL you mentioned above is archive page of post type "Jobs"
hidden link
2) You are using Views WordPress Archive "Archive - Job" to design above archive page:
hidden link
3) In above Views WordPress Archive "Archive - Job",
- in section "Query Filter", it is using below filter:
Select items with field:
Job - Profession is a string equal to URL_PARAM(wpv-wpcf-job-profession)
So the custom field "Job - Profession" is registered in post type "jobs"
- in section "Output Editor", there is a view's shortcode:
[wpv-view name="ads-serp"]
4) Above post view "Ads - SERP":
- Query "Ads" posts
- Filter by:
Select posts in a Ad - Profession relationship that are related to the Post with ID set by the URL parameter _sfm_wpcf-job-profession.
eg. hidden link
I assume you are going to use custom field "Job - Profession" of "Jobs" post to filter another post type "Ads".
If it is, it is not possible within Views plugin yet, since there isn't field "Job - Profession" in post type "Ads", so it won't be able to work, and it is expected to display the result: No items found
hidden link
In my opinion, you might consider this:
1) Create another post view "related-ads-posts":
- Query ADs posts
- Filter by post type relationship between "Jobs" and "ADs" of The current post in the loop
2) Put above post view "related-ads-posts" insider loop of WordPress Archive "Archive - Job", so you will get some result like this:
- Jobs A
-- related ADs 1
-- related ADs 2
...
- Jobs B
-- related ADs 3
-- related ADs 4
...
More help:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items
Hi Luo,
Thanks for your response. I followed your steps but there no items show up yet: hidden link
This is the view: hidden link
Can you make some changes to let this work?
Thank you,
Menno
Oh i see hidden link this looks great. But the ads are now between the posts and i would like to have 3 at the top like Google Ads.
I have done below modifications in your website:
1) Edit the post view "Ads - Related post ads"
hidden link
in section "Query Filter", change the filter to:
Select posts in a Ad - Job post relationship that are a related to the current post in the loop.
2) Edit the WordPress Archive "Archive - Job":
hidden link
- in section "Loop item in Archive - Jobs", at the bottom, add above post view's shortcode:
[wpv-view name="ads-related-post-ads"]
- in section "Output Editor", remove above shortcode
3) Test it in front-end:
hidden link
You should be able to see the related ADs post
As I mentioned above, you can display the result like this:
https://toolset.com/forums/topic/filter-view-by-text-instead-of-id/#post-1314451
- Jobs A
-- related ADs 1
-- related ADs 2
...
- Jobs B
-- related ADs 3
-- related ADs 4
...
Since there isn't field "Job - Profession" in post type "Ads", so that relationship filter won't work, hope it is clear.
Yes this looks great but is there a way to bundle all related ads to three ads at the top?
Is it possible to query posts that equal these 2 fields job-profession and ad-profession?
I don't think there is such kind of built-in feature within Views plugin, you will need to consider custom codes, but according to our support policy, we don't provide custom codes support, you can check it with our Toolset Contractors:
https://toolset.com/contractors/
Alright. Thanks for your support but this is not the way the ads should work. The ads now show up directly under the post.
I would to have it like Google Ads where there are 3-4 ads at the top (not between posts) that are related to the posts that are in the loop. I will take a look at the contractors page.
OK, feel free to create new thread if there is new questions.