Skip Navigation

[Resolved] How to display related Posts based on custom fields?

This support ticket is created 4 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 24 replies, has 2 voices.

Last updated by Beda 4 years, 6 months ago.

Assisted by: Beda.

Author
Posts
#1345119

Hi,
I have a job website where we publish job posts (news) made with custom fields and Repeatable Field Groups (RFGs). Now I want to display related job posts (Jobs having some similarity) in the single job post bottom. Please tell me how to achieve that? Thanks.

#1345253

You would use Toolset Views to create lists of any kind.

Hence that's where we start, in Toolset > Views > Add new.

Choose, by default, the "Full custom display mode", this will make sure all possible features are open for usage in the View.
Then choose the Posts you want to display in your list (no matter what the similarity shall be, we do this later).
Just select that post type that you want to display data of, so in this case it should be "jobs" post type.

Next we need to filter posts that are "similar" to some other post.
Here, it matters how you decide on the website that some posts are more similar than others. Do you use a Taxonomy to "connect" them, or is the "similar" data only coming from Toolset Fields?
Depending on where the similarity is in, you will create a Query Filter for that item (field, or taxonomy, or what is used for the "relation/similarity")

You can choose different comparisons methods, so for example, if you would be comparing Number fields in Jobs (lets say, you want to show jobs with a greater salary than the current), you would choose a Query Filter for the "salary" field, and choose to return items with a value greater than your Salary Field.

You will be prompted to determine from where precisely the data to compare should come from, and you have a few choices here, the best in your case will be "shortcode attribute", because that allows to re-use the View dynamically on many posts passing always the salary just of that one post as comparison operators.

Further down the View you can insert in the Loop Editor all data you want to display of those Jobs with a salary greater than, and finally, you can create a Content Template, assign that to your Jobs, and in the Template, insert the view you created.
Remember to pass the correct values to the ShortCode Attributes you created, you can do so in the GUI, when inserting the View.
You can even pass ShortCodes within those Attributes, so you can use the ShortCodes for the actual Salary field, as comparison value.

This will allow the view to dynamically get each current's post salary field and compare it to the others posts salaries, then output only what's greater than the current jobs salary.

I suggest reading about Views first here https://toolset.com/home/toolset-search/, then you can dive in the Search and Queries: https://toolset.com/documentation/user-guides/front-page-filters/

#1345841

Thanks for your support. Let me try some of your suggestions. Please keep the ticket open for some more days till I prepare something logical and informative for my viewers.

#1346131

Hi,
I have created views for related posts and inserted it in the Single 'Job' Post template. You can see it hidden link

But the problem is I want to show similar job vacancies based on 'Job Type' custom field (RFG). But it's showing something else that's don't even match. How to solve the issue? Please help.

#1346909

This is not possible.

You can query views by fields of the post type you query in it.
So if your View lists "post type A" and that post type has a Repeatable Field Group "Group B" then you cannot query or filter the Post Type A View for fields in that Group B.

What you can do is list Group B Repeatable Field Groups in a View and then filter those by the fields in the groups.
You can then in the Loop of this View, display the parent posts (so the post where the Repeating field group belongs to).

You can not set up front end searches for those Repeatable Field Groups in such views, though, as it's not yet supported in the GUI to "add new filters".
It's only supported in the "Query Filters".
I have added your voice to the request that should allow such filtering.

For now, you have to do this manually, and I cannot guarantee that once it's added to Toolset Views the syntax will be exactly as follows.

1. Add the Query filters for the Fields in the Repeatable Field Group in the View of Repeatable Field Groups
2. Get the slug of the Fields you want to query by, and in the HTML Front End Search editor you can add for each field:

<div class="form-group">
	<label for="wpv-single-field-in-rfg">[wpml-string context="wpv-views"]single-field-in-rfg[/wpml-string]</label>
	[wpv-control-postmeta field="single-field-in-rfg" type="select" url_param="wpv-single-field-in-rfg"]
</div>

Remember that for each field you will need to adapt above code.
3. In the loop I can show current Field, Current RFG and Post (parent):

PARENT POST: [wpv-post-title item="@rfg-fields.parent"] <br> 
Current RFG: [wpv-post-title] <br>
The Field of RFG: [types field="single-field-in-rfg"][/types]

Depending on the requirements, it might be easier to currently not use Repeatable Field Groups for this "comparisons" View but only single fields.

#1347075

Sorry I couldn't understand what are you pointing for. But see I have created views with RFG. See this page hidden link
This has been created with post ids as a query filter.
Please have a look. Thanks

#1347081

What I mean is that you can not create a View, that queries Custom Posts, and filter in fields of Repeatable field groups belonging to it.

Also you can not create a View, that queries Repeatable Field groups and create a front end filter for the fields in those groups, unless you apply the manual solution as above shown, which is currently not officially supported.

Hence you cannot create such a view, as long the fields are in a repeatable field group.

#1347099

Ok. See I am not that expert. If I give you access to my site can you create?

#1347109

But as I state, there is no way to create this, with Toolset, with officially supported methods yet.

I can also not create this for you, the Toolset Support Policy does not allow me that (https://toolset.com/toolset-support-policy/)

I can guide you thru each step and explain each feature, and also make example content.

I have enabled a private form for you to provide me access to a testing site, in case this becomes necessary.

First, you will need to decide wether you want to use the yet unsupported way of filtering a View with Repeatable Field Groups, or if you could switch those fields to be single fields (which would allow to filter posts by those fields and hence, also find similar posts).

It will be restricted, if we choose the way of manually adding filters, it may work or not without custom code, we will need to see this along with the requirements you will have.

If we use single fields we can directly query in the View.

You can create the fields in Toolset > Custom Fields.
Note that if you decide to drop the RFG (Repeatable Field Groups), you will additionally want to delete the actual saved fields, that would be done under Toolset > Custom Fields > Custom Fields Control.
If you stick wit the RFG Fields, you do not need to touch that.

In either case the next is to create the View, which queries the Post Type we want to return (we want to show in the results).
As said, it will be much easier if these posts are the actual posts we want to see, and hence we would use Single Post Fields.

Could you achieve your goal as well using single post fields?

#1347135

Well at the moment I cannot switch back to single custom field discarding the RFG. Because the entire individual job data has been created using RFG. Even I was planning search filters based on those RFG data on the front end. Now you are saying it can't be done.
Can I not filter data for the page hidden link on the front-end? But I can create a query filter for those (RFG) fields in the backend like displaying Job posts having 'No. of Vacancies' of more than 5. It works pretty well. So why not on the frontend?

#1347137

I mentioned, Query Filters can be created.
You can then, since you can add Query Filters, also add the HTML and shortcodes for the front end search but as said that is not yet officially released, so I can simply not guarantee it will work in future (the front end filter).

So, currently, you can not filter in the front end by those fields if you want to use what surely will be supported which can only be an officially released feature, which now is simply missing.

We could surely help later to re-adjust, if there would be anything failing after an eventual update, I however generally dislike to implement something if I am not 100% sure it will work like that as well in future.

If you want I can set up an example of such search for you in that View, I would however need access to it.

Thanks!

#1347199

Let me clarify one thing that I have seen in Toolset views 3.0-b1 version that

"Introduced the new Views block as a visual way of creating and editing Views:
Generate lists with pagination and sorting controls.
Generate search forms with all the usual Views available filters.
Live preview of the View outcome, with real data."

Will that solve my issue? If not is there any plugin (like WPSOLR) that can solve my problem?
Thanks

#1347223

I had a look at hidden link

I see in this page you inserted the "list-job-post-details-posts" View (hidden link)
There, the RFG "Job Post Details" is queried.

However, that same view has a query filter to get only the posts that have an IDs set by the View shortcode attribute "ids" eg. [wpv-view name="view-name" ids="1"]

When inserting the View in the page I see you pass another View as ID attribute: parent-view-expired-job-posts-within-7-days (hidden link)
This View, queries Jobs and will give us only the Jobs that have as Last Date of Application/ Date of Interview a number (timestamp) between PAST_DAY(7), PAST_DAY(1) (so between the last 6 days of past-yesterday).

The Loop in this View here is however not returning (as I expected) a set of IDs that the other view could use for its View ShortCode attribute, it calls once more a View "child-view-expired-job-posts-within-7-days" (hidden link)
Now this view again queries the RFG "Job Post Details", and only those that related to the current post in the loop.

Finally, this View gives us Post ID of those RFGs.

So ultimately, when we insert list-job-post-details-posts, which will return RFG posts related to the posts passed in its shortcode attribute), it will try to get posts related to the ID as given by child-view-expired-job-posts-within-7-days.
That View's Output however, a commaseparated list, will repeat for its parent View parent-view-expired-job-posts-within-7-days for each post found there, and that View, will then produce the repeating comma separated lists of ID's to the final View.

When we visit hidden link, we see the output of "List Job Post Details posts" View, I added a small string to show that in the front end, and I see only posts that are from before past-yesterday and none past 7 days before today.

The setup is particular but seems to output the right data?
Now, you want to restrict this list even further by querying the RFG Fields, do I understand correctly?

Related to hidden link, there I see that you use a Content Template where the View "parent-view-related-post" (hidden link), which queries "Jobs" that have a Last Date of Application/ Date of Interview field greater than or equal TODAY(), and then in it's loop, for each of those Jobs, it will display all RFGs belonging to it as determined in the View "related-posts" (hidden link)

Do you want this to return only the RFG that are similar to the ones of the current post where the Parent View is inserted?

That is not possible, in both cases, because it will query distant posts fields (so, it will query fields of another post type while listing a specific post type). But maybe there is a chance.

See, you could add a (query or front end)( search for Fields in RFGs in this view for example:
hidden link

Since you list all RFGs of All jobs found, and now want to restrict that list to the ones similar to the RFG's of the Job where the View is shown, you would need to compare in the query, the Custom Field in the RFG, against the Custom Field in the RFG of the Post where the view will be inserted to.

That could be done by adding the query filter to the the view and telling it to listen to the ShortCode attributes.
Then in the parent view, use the $current_page to get the field value of the current page where the view is inserted to, to receive that RFG's

But the current page will not be the RFG, it will be it's parent post, and hence we would need a View, to get the current page^s RFG and pass that to the View as shortcode attribute, but this won't work with many RFG's as returned results passed to the query.

Unfortunately I see no solution for this in this scenario

I will test if I can find some other solution, where the goal would be, to display RFGs that are similar (lets say, have the same value for a given field) across many posts.

I will then update you here with what I find (I am relatively sure there is no viable solution for this, but I will confirm)

#1347229

Your replies crosse, in reply to:
https://toolset.com/forums/topic/how-to-display-related-posts-based-on-custom-fields/#post-1347199
It will not resolve your issue, this is what Toolset can do already.
There is no plugin that can query this data, Custom Code could, eventually.

Toolset Developers are in progress of enhancing the Relationships in Toolset at every time of development, and they also accept feature requests if you see missing features, like things that you think should be possible, but are not:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

The queries as needed here are all filed as requests, but they will require more time to be implemented.

#1347757

So what you suggest at the moment. How can I display the related job positions? Any alternative way I can go for?

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