Skip Navigation

[Résolu] how get the id of the previous post for [wpv-post-next-link]?

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
Setup links to parent post, the link text is a custom field value of parent post.
I wrote a shortcode [next-post-id] to get the id of the next post.

function shortcode_next_post_id ($atts)
{
   global $post;
   $next_post = get_next_post();
   if (empty ($next_post))
        return 0;
   return $next_post->ID;
}
add_shortcode('next-post-id', 'shortcode_next_post_id');

Solution:
Since you have already got the post ID of next post with custom shortcode [next-post-id], so you can setup the link manually with HTML code, for example:

<a href="[wpv-post-url id=[next-post-id]]"> [types field='rs-brandname' id='[next-post-id]'][/types]</a>

Please make sure you have already registered the custom shortcode name in the Toolset setting page:
Dashboard->Toolset-> Front-end content
option "Third-party shortcode arguments", fill the custom shortcode name: next-post-id

Relevant Documentation:

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.

Marqué : ,

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

Last updated by Luo Yang Il y a 4 années et 1 mois.

Assigned support staff: Luo Yang.

Auteur
Publications
#568430

I am trying to:
Show next post with [wpv-post-next-link format="%%LINK%% »" link="Next post: %%TITLE%%"]
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-next-link

I don´t want to see the %%TITLE%%, but want to so a custom field (rs-brandname) of the next post instead.

So i wrote a shortcode [next-post-id] to get the id of the next post.

function shortcode_next_post_id ($atts)
{
   global $post;
   $next_post = get_next_post();
   if (empty ($next_post))
        return 0;
   return $next_post->ID;
}
add_shortcode('next-post-id', 'shortcode_next_post_id');

I expected to see a link for next post with brandname with this shortcode:

[wpv-post-next-link format="%%LINK%% "" link="[types field='rs-brandname' id='[next-post-id]'][/types]"]

But i just always see the brandname of current post.

What works fine is [types field='rs-brandname' id='[next-post-id]'][/types]

next-post-id is insert in Toolset/setting as third party shortcode.
What i am doing wrong?

#568446

Luo Yang
Supporter

Languages: Anglais (English ) Chinois simplifié (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Dear Mario,

Since you have already got the post ID of next post with custom shortcode [next-post-id], so you can setup the link manually with HTML code, for example:

<a href="[wpv-post-url id=[next-post-id]]"> [types field='rs-brandname' id='[next-post-id]'][/types]</a>

Please make sure you have already registered the custom shortcode name in the Toolset setting page:
Dashboard->Toolset-> Front-end content
option "Third-party shortcode arguments", fill the custom shortcode name: next-post-id

#568543

Thank you so much.

#568577

Luo Yang
Supporter

Languages: Anglais (English ) Chinois simplifié (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

You are welcome