Skip Navigation

[Resolved] Looking to include some text from a custom field with prev/next post links.

This support ticket is created 4 years, 9 months ago. 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
- 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)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by calgaryA 4 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#1553711
prev-next-post.jpg

Wondering how I can include some text from a custom field within the prev/next post links.

Currently on my single.php template file, I've included the WordPress prev and next post links at the bottom of the page. However, when I pull the custom field info for the Episode Number it pulls the episode number for the current post. Wondering how I can access the custom field (types_render_field('episode-number') in the prev and next posts.

The prev post should be Episode 1, next post should be Episode 2.

Thanks in advance!

#1553961

Shane
Supporter

Languages: English (English )

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

Hi Calgary,

Thank you for getting in touch.

In order to do this it will take some manipulation of Data. WordPress has a built in function to get the previous and next post link for the pagination.

They also have a function to get the next and previous post itself.
https://developer.wordpress.org/reference/functions/get_previous_post/

https://developer.wordpress.org/reference/functions/get_next_post/

Whilst i'm not able to write the code for you, I can advise you on what is needed. Both the functions above get the post objects for the previous and next post respectively.

What you will need form them is the ID of next and previous post


$previous_post = get_previous_post();
$previous_id = $previous_post -> ID;

$next_post = get_next_post();
$next_id = $next_post -> ID;

Now that you're able to get the ID you can pass this into the Types function to get the custom field data to manually select the post you want the field data from.

Please let me know if this helps.
Thanks,
Shane

#1554067

My issue is resolved now. Thank you!