Skip Navigation

[Résolu] How to get related posts with a dynamic parent post ID

This support ticket is created Il y a 2 années et 9 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 3 réponses, has 2 voix.

Last updated by Shane Il y a 2 années et 9 mois.

Assisted by: Shane.

Auteur
Publications
#2097777

Tell us what you are trying to do? On this link: hidden link we have a review. this review is having a relationship - using one field too:

Conducted tour: <a href="[wpv-post-url item='@product-review.parent']" target="_blank" rel="noopener">[types field='short-titel' item='@product-review.parent'][/types]</a>
<span class="mytourid">[wpv-post-id item='@product-review.parent']</span>

On the same post-page, we like to have related posts (reviews) where used on the parent post (respectively child post).

First question: How do I set the filter of this view?

By the parameter fixed with the number, it is working:

[wpv-view name='related-reviews' wpvrelatedto='3879']

But we like to get it "dynamically"... - so is it possible to have a shortcode instead of a fixed number? Something like this:

[wpv-view name='related-reviews' wpvrelatedto='[wpv-post-id item='@product-review.parent']']

Is there any documentation that you are following? I didn't found a document for the legacy view creation anymore.

The second question is, how do I set this view, to get infinite scrolling pagination? So that it shows first 6 related posts, and then when the customer is scrolling down, it will showing all the times 3 more.

Is there a similar example that we can see? hidden link

What is the link to your site?

#2098073

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Fred,

Thank you for getting in touch.
But we like to get it "dynamically"... - so is it possible to have a shortcode instead of a fixed number? Something like this:

[wpv-view name='related-reviews' wpvrelatedto='[wpv-post-id item='@product-review.parent']']

This is exactly the way to do it, given that you want to dynamically get the parent ID of the current post. However I would format it a little different so that the quotations don't get closed early. Use the one below.

[wpv-view name='related-reviews' wpvrelatedto="[wpv-post-id item='@product-review.parent']"]

Notice the use of the double quotes.
The second question is, how do I set this view, to get infinite scrolling pagination? So that it shows first 6 related posts, and then when the customer is scrolling down, it will showing all the times 3 more.

When you are doing the pagination there is a fixed number of items per page. What this means is that you won't be able to start your view with 6 posts and then paginate by 3 posts. If the view is started with 6 posts then the pagination will bring the next 6 posts when scrolling down.

To enable the infinite scroll pagination, you will need to first edit your view then scroll to the "Pagination and Sliders Settings" if you're not seeing this scroll to the top of the edit screen and click screen options in the top right then enable it there.

Now once the section is enabled select "Pagination enabled with manual transition and AJAX" under "Transition effect: " select Infinite Scroll.

Please let me know if this helps.
Thanks,
Shane

#2098657

Dear Shane

About the first part - is there another way to do it? Somehow the theme we use isn't 100% compatible, and having some small issues with show everything correct:

hidden link

I got this on the end of the view, I get a "]

I did this now, and it seems to working

function get_my_tour_id () {
	global $post;
	$mytourid = get_post_meta($post->ID, 'wpcf-my-tour-id', true);
	echo do_shortcode ('[wpv-view name="related-reviews" wpvrelatedto="'.$mytourid.'"]');
	//return $mytourid;
}
add_shortcode('show_my_tour_id', 'get_my_tour_id');

echo might also not working here...

#2099287

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Fred,

I know that for some theme or page builders when using their shortcode editor you will get a broken "] at the end because they aren't compatible with nested shortcodes.

Secondly you should just be able to return the do_shortcode() function.

So using the return would be fine.

Thanks,
Shane

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