Skip Navigation

[Resolved] How to filter view with shortcode attribute to display similar or related posts section

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

Problem:
How to filter view with shortcode attribute to display similar or related posts section based on taxonomy terms

Solution:
As its not possible to filter the block view using the shortcode attribute, you have to create the view in classic mode.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/similar-posts-2/#post-2370665

Relevant Documentation:
- https://toolset.com/course-lesson/enabling-legacy-version-of-toolset-views/

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by leilaG 1 year, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2367043

We would like to display a block of 4 similar posts at the bottom of a post.

That are:
- Same field: Location
- Same field: Type of space
- The 4 posts that are the closest number to field: sq. ft.

How do we achieve that?

hidden link
See bottom of page for image example

We started by copying the content template from this page - hidden link
Updated the view name
Removed the search bar
but the search bar is still showing (button of the page) - hidden link

#2367637

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

When you duplicate template - did you try to create another view, as your purpose to display the related posts based on some field conditions.

Can you please share admin access details and tell me what template you duplicated once I review your current settings I'll be able to guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2369099

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

On this page I can see one view with search form on left and search result on right and at bottom of the page.

Do you mean you want to remove the search form and only display the related property based on the current post field location value, type of space value and closes number of sq. ft.?

#2369189

Yes, that is what I mean. How can we achieve that?

I copied the content template so that I didn't need to recreate all the same styling.

This is the copy - hidden link
When I removed the side bar in the template, it was still showing in the page. Even though I changed the view name and CT name. Not sure why that happens?

Thanks

#2369211

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I see the following content template is assigned to post type "space" to display single space posts:
=> hidden link

I've disabled the search for the view at top but still when I check on the frontend it shows another view with search at bottom:
=> hidden link

Are you building the site with Toolset only or have you defined view anywhere else?

In addition to that, to filter the view with current post values, you will have to build the view in classic mode as we will require to pass the current post values as view's shortcode attribute.

#2370169

Are you building the site with Toolset only or have you defined view anywhere else?
I'm not sure what you mean by this?

The page template is built here, where the toolset codes are - hidden link

We basically want to create a 'Similar posts' section at the bottom of the individual space pages - hidden link

#2370665

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As its not possible to filter the block view using the shortcode attribute, we have to create the view in classic mode.

I've created the following view in classic mode:
=> hidden link
Where:
- As you can see I've added the Query filters for taxonomy locations and spacetypes as well as sq. ft. custom field.

Taxonomy filter:

Select posts with taxonomy:
Locations slug in one of those set by the View shortcode attribute wpvlocation
eg. [wpv-view name="view-name" wpvlocation="xxxx"]
AND
Space types slug in one of those set by the View shortcode attribute wpvspacetype
eg. [wpv-view name="view-name" wpvspacetype="xxxx"]

Custom field filter:
Select items with field:
Sq. Ft. is a number between 0, VIEW_PARAM(sqvalue)

Then, to the content template you created I've added the above view as given under:
=> hidden link

[wpv-view name="display-related-spaces-posts" wpvlocation="[wpv-post-taxonomy type='location' format='slug']" wpvspacetype="[wpv-post-taxonomy type="space-type" format="slug"]"  sqvalue="[types field='sqft' output='raw'][/types]" cached="off"]

Could you please test.

It should list the posts if it found any matches where:
- taxonomy location is same as current post
- taxonomy space type is same as current post
- custom field sq. ft. value between 0 to the value of current post of sq. ft. custom field
(we do not have any artificial intelligence to apply to determine what would be the closest value)

as you can check with the following post:
=> hidden link
It shows "no items found" under the "Similar spaces":

You can add whatever content you want to display with the single space content template:
=> hidden link

#2372511
similar-spaces-list-view.png
main-search-filter.png
similar-spaces.png

Thank you very much Minesh.

As the we can not get the closest value of the sq.ft I have removed this filter. The similar spaces are now showing as a List -
hidden link
If I want to style this like they are in the image example similar space, is this done in the VIEW? - hidden link

Also I wanted to check what happened to this page -hidden link
The main search and results seem to have disappeared
You can see how this should be on the live site - hidden link

I want to make sure when I recreate this on the live site, that I do not loose the main search and results page - hidden link

#2372599

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You can build the view's template using blocks, click on button "Edit with block editor" and you can format your view output as desired.
=> hidden link

To do that, you should first click on "Loop Wizard" button and select your output and then add any field for now and then you can use the feature "Edit with block editor".

Also I wanted to check what happened to this page -hidden link
The main search and results seem to have disappeared
==>
You should try to add your view as in my testing I must have removed the view that you added to find your lab page.

#2372647

My issue is resolved now. Thank you!

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