Skip Navigation

[Gelöst] How to filter view with shortcode attribute to display similar or related posts section

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

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 support ticket is created vor 2 Jahren, 6 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 9 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von leilaG vor 2 Jahren, 6 Monaten.

Assistiert von: Minesh.

Author
Artikel
#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?

versteckter Link
See bottom of page for image example

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

#2367637

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: 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

Sprachen: Englisch (English )

Zeitzone: 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 - versteckter 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

Sprachen: Englisch (English )

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

I see the following content template is assigned to post type "space" to display single space posts:
=> versteckter 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:
=> versteckter 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 - versteckter Link

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

#2370665

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: 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:
=> versteckter 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:
=> versteckter 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:
=> versteckter 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:
=> versteckter 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 -
versteckter Link
If I want to style this like they are in the image example similar space, is this done in the VIEW? - versteckter Link

Also I wanted to check what happened to this page -versteckter Link
The main search and results seem to have disappeared
You can see how this should be on the live site - versteckter 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 - versteckter Link

#2372599

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: 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.
=> versteckter 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 -versteckter 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!