Skip Navigation

[Résolu] wpv-post-next-link not working properly

This support ticket is created Il y a 1 an et 8 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 – 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: Asia/Karachi (GMT+05:00)

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

Last updated by Ido Angel Il y a 1 an et 8 mois.

Assisted by: Waqar.

Auteur
Publications
#2438783

hi
I've entered this shortcode in elementor template for single "work" (custom post type):

[wpv-post-next-link format="%%LINK%%" link="Next Hand"]

It leads to the same post in all posts, and in the actual post it leads to - the button isn't seen at all.

you can see here:

hidden link
hidden link
hidden link
hidden link

in all the above, pressing "next hand" leads to the same post - hidden link - and in the "briefly" post the button isn't showing at all
thx!

#2438855

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+01:00)

Hi there

I expect the problem is that when using an Elementor template the context of the current post is lost to such Toolset shortcodes.

Can you try the same in a template made with Toolset?

I suspect it may work if you add the shortcode to an unassigned Content Template and then insert that template (via the wpv-post-body shortcode) into the Elementor template, rather than inserting the shortcode directly.

#2438875

Hey Nigel

Still doesn't work.
I created an unassigned content template with the shortcode and called it "next shortcode".
Then I inserted the shortcode into the elementor single post templet like this:

[wpv-post-body view_template="next-shortcode"]

but the situation remains the same

#2439293

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for sharing this update.

Can you please test if it makes any difference when the current post's ID is specified, through the 'item' attribute:


[wpv-post-body view_template="next-shortcode" item="[wpv-post-id]"]

In case, it still doesn't work, you're welcome to share temporary admin login details so that we can see exactly how the Elementor template is set up.

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

#2440029

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing the access details.

For the 'next' and 'previous' post links, the published date is used for deciding the adjacent posts.

And if you check the published dates of your website's "Works" posts, there are just two groups based on the published dates.
( screenshot: hidden link )

a). 2 posts are published on 2022/08/01 at 8:12 am
b). The rest of the 38 posts are are published on 2022/08/01 at 8:04 am

( the exact same published dates suggest that these posts were imported )

For the 'next' and 'previous' post links to work correctly, you'll need to make sure that these posts have distinct published dates, so that they can follow an order.

#2440035

I see, thanks Waqar.
I indeed changed the minute of publication hour in each post and now that works. But the question is, is there a way to make this work not according to time, but alphabetically, because in the future I will import posts via wp-all-import, which would make some posts import at the same minute and I don't want to go over manually and change dates all the time...
thanks!

#2440049

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

You're welcome and glad I could help.

The Toolset's shortcodes for the next and previous links, use WordPress standard functions to get the adjacent posts.

To change the criteria to the post titles, you'll need to include some custom functions with relevant filters.

You'll find a good code snippet example in this forum reply:
https://wordpress.stackexchange.com/a/166933


function filter_next_post_sort($sort) {
    $sort = "ORDER BY p.post_title ASC LIMIT 1";
    return $sort;
}
function filter_next_post_where($where) {
    global $post, $wpdb;
    return $wpdb->prepare("WHERE p.post_title > '%s' AND p.post_type = '". get_post_type($post)."' AND p.post_status = 'publish'",$post->post_title);
}

function filter_previous_post_sort($sort) {
    $sort = "ORDER BY p.post_title DESC LIMIT 1";
    return $sort;
}
function filter_previous_post_where($where) {
    global $post, $wpdb;
    return $wpdb->prepare("WHERE p.post_title < '%s' AND p.post_type = '". get_post_type($post)."' AND p.post_status = 'publish'",$post->post_title);
}

add_filter('get_next_post_sort',   'filter_next_post_sort');
add_filter('get_next_post_where',  'filter_next_post_where');

add_filter('get_previous_post_sort',  'filter_previous_post_sort');
add_filter('get_previous_post_where', 'filter_previous_post_where');

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

#2441881

My issue is resolved now. Thank you!

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