Saltar navegación

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

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

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 hace 2 años, 8 meses. 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
- 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)

Este tema contiene 9 respuestas, tiene 2 mensajes.

Última actualización por leilaG hace 2 años, 8 meses.

Asistido por: Minesh.

Autor
Mensajes
#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?

enlace oculto
See bottom of page for image example

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

#2367637

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: 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

Idiomas: Inglés (English )

Zona horaria: 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 - enlace oculto
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

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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

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:
=> enlace oculto

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 - enlace oculto

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

#2370665

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: 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:
=> enlace oculto
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:
=> enlace oculto

[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:
=> enlace oculto
It shows "no items found" under the "Similar spaces":

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

#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 -
enlace oculto
If I want to style this like they are in the image example similar space, is this done in the VIEW? - enlace oculto

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

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

#2372599

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: 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.
=> enlace oculto

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 -enlace oculto
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!