Skip Navigation

[Resolved] Prev and Next based on CPT custom field number

This support ticket is created 6 years, 6 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 – 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/Hong_Kong (GMT+08:00)

This topic contains 9 replies, has 2 voices.

Last updated by Luo Yang 6 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1082742

pjF
Edit_View_‹_Cayenne_Diane_—_WordPress.png

Tell us what you are trying to do?
Create Previous and Next links based on a number that is equal to or lower/higher than the currently displayed post.

Is there any documentation that you are following?
Yes-but the filter component doesn't seem to allow this
Is there a similar example that we can see?

What is the link to your site?

What I would like to do is take the current value of a post and compare it to the previous and next posts as seen sorted by this field. When I create a view loop of these posts, everything is output in the correct order. I just want the Prev/Next links to follow this sorting.

I've attached a screenshot of what I'd like to do, but I don't know how to format the query via URL_param or Shortcode so that it works.

#1082788

Hello,

Please describe the questions with more details:
Create Previous and Next links based on a number that is equal to or lower/higher than the currently displayed post.

How do you setup the custom number field?
How do you setup the Previous and Next links?

Are you we talking about this case, you are order the view result by a custom field "Scoville ...", see your screenshot:
hidden link

and there are pagination settings in the view, after click the pagination, the view does not respect the "order by" setting?

If it is, then the problem is abnormal, please check these:
1) In case it is a compatibility problem, please deactivate other plugins, and switch to wordpress default theme 2017, and test again

2) If the problem still persists, please provide database dump file(ZIP file) of your website, also point out the problem page URL and view URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#1083538

pjF
Edit_View_‹_Cayenne_Diane_—_WordPress.png

I'm trying to create custom post previous and next links so users can page through a list. Rather than Post Title or by date, I want to sort by a custom value in each post. There are over a hundred CPTs in this category, so the number could be higher, lower, or the same. I have set up secondary sorting by Post Title for cases where the value is the same.

I am not sure of the best practices to create this. My first thought is to create a View that is only the Previous result and a separate one for the Next result.

I have tried creating a View with pagination to show nothing but the prev/next links. I am not sure how to get this to work yet.

So far, my individual previous view result always gives the lowest value of all Types posts with this field, rather than the next lowest value. This happens with or without a filter. (Sorting by descending in this case)

Essentially, what I need is the Next and Previous links that wordpress provides, but sorted based on a custom field number in my Types custom posts.

#1083599

I assume you are going to do these:
1) A custom post type "my-cpt"
2) Each "my-cpt" post has a field "my-number", for example:
Post A, "my-number" value is 1
Post B, "my-number" value is 2
Post C, "my-number" value is 2
Post D, "my-number" value is 3

you are going to display the view pagination result as below:
Page 1
- Post A
Page 2
- Post B
- Post C
Page 3
- Post D

If it is, I suggest you try these:
1) Setup custom taxonomy "my-number", and register it to post type "my-cpt"
Setup each "my-cpt" post, and setup the "my-number" value

2) Create a two views:
a) First taxonomy view, list terms of taxonomy "my-number", order by the the term's name, display a link and pass URL parameter (term's id) to the target page
b) Second post view, list posts of post type "my-cpt", and filter:
Taxonomy term ID is set by the URL parameter "terms-filter"

Then display both above view in same page, it should be able to achieve what you want.

#1084664

pjF

This is almost what I want-- I'm really trying to replicate the functionality of WordPress's Previous and Next, which is based on the post date--but override it with a custom field in my cpt. So the example you show would be similar, but it would just be the posts themselves going in order from ABCD, not a listing of the pages.
Setting up a new taxonomy defeats the purpose of having the existing data.
In the past, we've "hacked" this by setting dates for each post to a date in the past, but in chronological order that matches the scovilles ordering. As the database grows, this becomes more tedious, so we'd like to avoid it ?
Also tedious would be moving or copying the existing data into taxonomies.

Thanks for helping, by the way! Any advice on how to accomplish this?

#1084921

What kind of a listing of the pages do you want?
is there any demo or screenshot for it? please describe the question with more details, I need to test it in my localhost, thanks

#1085415

pjF

Hello,

In this instance, the CPT is "Peppers". Each post within it contains information about 1 pepper. It's Name, Scientific name, heat rating (in Scovilles), description, and so on.
I currently have a View that lists these entries with summaries, and it is sortable and searchable and works great.

So once a person clicks on a pepper, they are taken to a full view of the pepper, more pictures, etc. At the bottom is a call to "explore more" with a link to return to the searchable view. On either side is a "Previous Pepper" and "Next Pepper" link.

That's what I need to get to work by checking the heat (scovilles) of the next hottest and previous hottest entries.

You can see this on my old version of the site here:

hidden link

It is using Types, but does not have Views implemented like my new site will.

An example pepper, scroll to the bottom of this page:

hidden link

This is currently using a "cheat" by working with the default behavior of WordPress that sorts by date. The hope is that we no longer have to use this cheat while using Views, as we are about to greatly expand the number of entries.

Thank you for your continued help!

#1085459

In a single post, you can display the previous link and next link with Views shortcodes:
[wpv-post-previous-link]
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-previous-link
This shortcode renders the link to the previous post, in relation to the one currently being viewed.

[wpv-post-next-link]
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-next-link
This shortcode renders the link to the next post, in relation to the one currently being viewed.

#1085788

pjF

I have tried these within my Content Template, and they just default to WordPress's date sorting.
However, I was able to build a view that is sorted by Scovilles, and use Full-Page reload Pagination limited to 1, with no filter controls, and that seems to work. I'm in the process of figuring out how to hide the current entry from showing up as the previous or next link, but that should be simple. The "don't include current post in result" is checked, but something is still making it show up.

#1087348

For the question:
hide the current entry from showing up as the previous or next link

I assume we are talking about the Views shortcode [wpv-pager-next-page] and [wpv-pager-prev-page], please check our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-pager-next-page
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-pager-prev-page

There isn't such an option or built-in feature to hide the current entry from showing up as the previous or next link.

In you case, you might consider custom codes, for example:
create some custom shortcodes to retrieve the next and previous page links
https://codex.wordpress.org/Function_Reference/get_adjacent_post