Skip Navigation

[Resuelto] Using • Don't include current page in query result • on intermediary post

This support ticket is created hace 3 años, 7 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9: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: Africa/Casablanca (GMT+01:00)

Etiquetado: ,

Este tema contiene 16 respuestas, tiene 2 mensajes.

Última actualización por Stephen Vaughan hace 3 años, 7 meses.

Asistido por: Jamal.

Autor
Mensajes
#1986697
Screenshot 2021-03-15 at 09.57.26.png
Screenshot 2021-03-15 at 09.57.14.png
Screenshot 2021-03-15 at 09.56.50.png

Tell us what you are trying to do?

On the site that I am working on there are a number of relationships. The main one is artist-members to their work (products) one-to-many. This is all fine.

But, there is also the route that I am working on which is many-to-many, exhibitions to the art works exhibited, many-to-many because an artwork can be exhibited again. Following the principal of posting once, displaying in different places, to make the site efficient I am targeting the same products in the first relationship. To attach a different template I am using t intermediary post type of the many-to-many relationship. I am showing a view that shows other artworks from the same exhibition (see image attached).

I am using a similar pattern I have used before where the view is created to draw the posts from the post type to be shown, then filtered with the addition of the Don't include current page in query result checked to exclude the post item in the intermediary post. In addition to this the setup follows this pattern. Make the view mentioned above, then insert it into a content template and then use the following shorted to add to the intermediary template with:

[wpv-post-body item="@exhibition-work.parent" view_template="template-for-other-exhibit-works"]

The other screenshots show this set up.

As you can see, in the screen shot of the front end result, the first print Maquis should be excluded. This is what I need to resolve.

___________________________________________
Is there any documentation that you are following?

I discovered that there are other shortcode patterns (other than the one I normally use) that can be used in the following documentation:

https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

Is there a similar example that we can see?

I use a similar pattern on one of my other sites:

enlace oculto (scroll down)

In this instance the relationship is one-to-many where my work is catalogued by year.

#1986947

Hello and thank you for contacting the Toolset support.

As you man know, Toolset has a view's debug mode that opens a popup for admin users with useful details about the rendered Toolset elements(Content templates, views, archive templates). You can activate the debugging mode in Toolset->Settings->Front-end Content->Debug mode.

The popup includes for example the underlying SQL query for a view. If you activate it you will see that the post that has been excluded is actually the post in the loop. In this case it will be the exhibition. While you want to exclude the work, where you have included the template for the exhibition(parent) using the shortcode:

[wpv-post-body item="@exhibition-work.parent" view_template="template-for-other-exhibit-works"]

I assume that the content template "template-for-other-exhibit-works" includes the view, right?
I would suggest that you edit the view to include the following modifications:
- Update the relationship query filter to take the parent from a view shortcode argument, instead of the post in the view, or the post in the loop.
- Add a query filter where the ID is different than the ID passed in a shortcode argument.
Then include the view directly, without using a content template:

[wpv-view name="name or slug of the view" parent_post="@exhibition-work.parent" post_to_exclude="[wpv-post-id]"]

parent_post and post_to_exclude would be the shortcode arguments that you will configure in the view's query filters. Does it make sense?

Please note, that block-based view does not accept shortcode arguments, the view needs to be created using the legacy editor. Or it needs to have the query filter altered using custom code

#1986987

Thanks Jamal.

I didn't spot the option in settings for the debug panel. Very useful. There is so much in Toolset that often these things get overlooked by me. I was just looking through the settings yesterday and there were a lot of interesting things that made me think that I need to go and find out what interesting thing I could do with them. Is there a crash course somewhere on all this?

I am going to study what you sent me and will get back to you if I need more help.

#1987221
Screenshot 2021-03-15 at 14.56.54.png

Ok so my reading of the instructions you suggested have brought me this far where the feedback suggests that I am doing this wrong? See my attached screenshot.

If I am starting this correctly with the filter selection then, when it comes to adding the arguments via parent_post and post_to_exclude, these are with the IDs of specific posts where I am expecting to have all this done dynamically without any specific posts in mind.

#1987235

We do have an article about the view's debug mode, but we don't have exhaustive documentation of all the settings for Toolset. Some of the settings are documented as side notes in different parts of the documentation.

I'll set this ticket as waiting for your feedback. It should keep it open for 3 weeks. Get back to us if you need further assistance.

#1987259

I just saw your last reply. The error message is probably about the underscores (_) in the shortcode argument. Try these:
- parent-post or parentpost instead of parent_post.
- post-to-exclude or posttoexclude instead of post_to_exclude.
Then use them as:

[wpv-view name="name or slug of the view" parentpost="@exhibition-work.parent" posttoexclude ="[wpv-post-id]"]

Let me know what you will get.

#1987315

Duplicate removed. My browser went on a caching holiday.

#1987423
Screenshot 2021-03-15 at 15.40.06.png
Screenshot 2021-03-15 at 15.36.32.png

So the changes to the following fixed the errors:

parentpost instead of parent_post.
posttoexclude instead of post_to_exclude.

And using my view slug:

[wpv-view name="other-exhibition-works" parentpost="@exhibition-work.parent" posttoexclude ="[wpv-post-id]"]

The output is becomes…

“]

Maybe the format is wrong on that so following the hints in the filters when closed I tried this instead:

[wpv-view name="other-exhibition-works" parentpost="@exhibition-work.parent" posttoexclude ="1"]

But it reverts to showing all images( products).

#1987441
Screenshot 2021-03-15 at 15.40.06.png
Screenshot 2021-03-15 at 15.36.32.png

duplicate removed

#1987605

Ooops, sorry for the mistake. This actually won't work " parentpost="@exhibition-work.parent" " "@exhibition-work.parent" make sense when used in the item attribute instead of a custom attribute.

I'll suggest the following:
- Create a custom shortcode.
- Inside of it, get the parent post using do_shortcode('[wpv-post-id item="@exhibition-work.parent"]').
- And get the current post using get_the_ID() or using do_shortcode('[wpv-post-id]').
- Then execute the shortcode with do_shortcode:

$parent_id = do_shortcode('[wpv-post-id item="@exhibition-work.parent"]');
$current_id = get_the_ID();
return do_shortcode('[wpv-view name="other-exhibition-works" parentpost="' . $parent_id . '" posttoexclude ="' . $current_id. '"]');

Does it make sense?

#1987739

It makes some sense to me.

I set this up as a function in the following manner and added it to my theme functions file:

function other_exhibits_shortcode_function() {
$parent_id = do_shortcode('[wpv-post-id item="@exhibition-work.parent"]');
$current_id = get_the_ID();
return do_shortcode('[wpv-view name="other-exhibition-works" parentpost="' . $parent_id . '" posttoexclude ="' . $current_id. '"]');
}

add_shortcode('other-exhibits', 'other_exhibits_shortcode_function');

I may need to return to this tomorrow as I think I need to look at this with a fresh mind.

#1988715

Ok. I'll set this ticket as waiting for your feedback until you get the chance to work on it.

All the best, Jamal

#1988781
Screenshot 2021-03-16 at 09.51.54.png
Screenshot 2021-03-16 at 09.49.53.png

Hi Jamal,

I'm back after a good night's rest.

So from my last addition above I attempted to add your snippet to and add_shortcode function. and then use the following as the shortcode.

[other-exhibits]

This didn't result in anything but, I set about investigating with the debugger you pointed me to yesterday.

This was interesting because in the initial presentation it shows Items found to be 0. But if I dig down further into the report I see an array listing all the posts for works connected to the exhibit. So it seems that while on one hand no items found, on the other it seems to create an array of the post ids. As well as this It never seems to get to eliminate the post (855 in this case).

So I have a little more work to do. Am I heading in the right direction?

NOTE: the issue in this ticket isn't urgent. If you have other tickets to attend to please see to those first. The site isn't live and is behind a maintenance page. I am using it to test and try out many new things. If you want access I can create an admin account and pass the credentials via the private channel.

#1989155

Thank you for your feedback. I actually will be on weekend tomorrow and thursday.

But, I'd like to get access to your website and help with this. So, I am setting your next reply to be private.

#1989289

Just to add, the function for the shortcode [other-exhibits] is in the child themes functions.php file.