[Resolved] Previous andnext post links, but limited to the same parent
This thread is resolved. Here is a description of the problem and solution.
Problem: I would like to add pagination between sibling posts in a one-to-many post relationship. The links should say "Next" and "Previous" and allow the User to easily paginate between sibling posts with the same parent post.
Solution: A custom shortcode is available to help create these links. See the links below for some code examples and customizations.
I'm want to add links to the next and previous post on a single artworks page such as this one: hidden link.
As you can see, I got that working, using the [wpv-post-previous-link] and [wpv-post-next-link] shortcodes. However, those will link to posts from different parents as well, whilst I need them to only link to posts from the same parents.
The syntax has changed and you only need to know the relationship slug now, not the post type slugs for parent and child. Let me know if you have questions about this.
Thanks Christian. I just need a bit more help: I want the links to say "previous" and "next" instead of the post title. I guess I need to replace the $title in this rule":
That seems to work, thanks. However, the original part of the code does code a fatal error when I try to edit the template:
Fatal error: Uncaught InvalidArgumentException: All provided arguments for a related element must be either an ID or a WP_Post object. in /home/artandcommunication.nl/public_html/artcommunicators/wp-content/plugins/toolset-blocks/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php:246 Stack trace: #0 /home/artandcommunication.nl/public_html/artcommunicators/wp-content/plugins/toolset-blocks/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php(177): OTGS\Toolset\Common\Interop\Commands\RelatedPosts->set_query_by_elements(Array, 'parent') #1 /home/artandcommunication.nl/public_html/artcommunicators/wp-content/plugins/toolset-blocks/vendor/toolset/toolset-common/inc/public_api/m2m.php(110): OTGS\Toolset\Common\Interop\Commands\RelatedPosts->__construct(0, 'artist-artwork', Array) #2 /home/artandcommunication.nl/public_html/artcommunicators/wp-content/themes/Avada-Child-Theme/functions.php(40): toolset_get_related_posts(0, 'artist-artwork', Array) #3 /home/artandcommunicati in /home/artandcommunication.nl/public_html/artcommunicators/wp-content/plugins/toolset-blocks/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php on line 246
There has been a critical error on this website. Please check your site admin email inbox for instructions.
Okay I think I will need to take a closer look at how this is implemented on your site to be able to give you an update. Is the theme editable in wp-admin? If so, I can log in and check it out. Please provide login credentials in the private reply fields here and I'll take a look.
Okay I edited your child theme's functions.php file and added the last three lines of code here after the $sibling_args array. This conditional structure will prevent fatal errors in the Block Editor when the parent ID is false-y because wpv-post-id has no related parent post ID for any reason:
Our policy is to address one issue per ticket, so I would prefer to continue discussing the sibling navigation issue in the current ticket. It looks like the other ticket was closed without a real resolution, so I will reopen that ticket momentarily and ask Jamal to follow up with you.