Site logo

Archived topic

Post Navigation ordered by Post ID and ACF label

5 replies · Started by Julien on November 10, 2022

Viewing posts 1–6 of 6

Dear GeneratePress team,

For the post navigation, I would like to make the following changes:
- I assume that posts are ordered by publishing date by default. Would it be possible to order them by post ID?
- In my posts, I have created an ACF field, and I would like to display it instead of the post title. Can it be done?

Thank you in advance.

Kind regards,

Julien

Hi Julien,

The Post Navigation is a WordPress core Feature. By default, it's ordered by date. It's quite complicated to alter, and it's also out of our scope of support. See here for what our support includes: https://generatepress.com/what-support-includes/

I found this thread however which may be insightful: https://wordpress.stackexchange.com/questions/73190/can-the-next-prev-post-links-be-ordered-by-menu-order-or-by-a-meta-key/73194#73194

It may be good to raise a topic here as well: https://wordpress.stackexchange.com/

With regards to replacing the Post Title with an ACF field value, it's possible. You may use a GenerateBlock Headline Block added through a Block Element - Page Hero for instance.

References: https://docs.generatepress.com/article/block-element-page-hero/
https://docs.generateblocks.com/article/headline-overview/#dynamic-data

The GB Headline Block can retrieve ACF text fields.

Hi Fernando,

Thanks a lot for your quick feedback and details. I will check on Stack Exchange regarding how to order by ID.

Regarding the ACF field, sorry if I wasn't clear enough. I would like to display this field in the post pagination and not on the article headline. By default, the loop is:
< "previous article title" "next article title" >

And I would like to display the following navigation:
< "previous article ACF field" "next article ACF field" >

There is any hook/filter to modify the pagination component?

Thanks in advance.

I wish you a great Friday.

Julien

Hi there,

sorry for delay, we missed your last reply.

There is the generate_post_navigation_args filter:

https://github.com/tomusborne/generatepress/blob/4895a2e7595bb809075b375201fd735112f41570/inc/structure/post-meta.php#L42-L52

That can be used to modify the paging links.

Heres an example that outputs the featured image with the title:

https://generatepress.com/forums/topic/next-previous-post-based-within-category/page/2/#post-1451510

Note how we use: $prevPost = get_previous_post(true); to get the ID using $prevPost->ID which you could use to get your ACF field.

Hi David,

No worries, thanks a lot for your feedback.

Thanks to the information that you shared, I was able to achieve what I set out to do.

Kind regards,

Julien

Glad to hear that!

This archived topic is closed to new replies.