- This topic has 9 replies, 3 voices, and was last updated 3 years, 5 months ago by
Fernando.
-
AuthorPosts
-
November 3, 2022 at 11:15 am #2400467
Jason
Hey y’all. I recently modified my custom post archives to display alphabetically and it threw my custom single-post pagination off. What am I doing wrong? I’m sure I need to add another filter for the pagination, but not sure the right way to do it. The pagination is a block element set to “post navigation” and then container links are dynamic set to “next” and “previous” posts, respectively.
Here is the code I used to modify the archive page
function foo_modify_query_order( $query ) { if ( ! is_admin() && $query->is_main_query() && ! $query->is_post_type_archive('happenings') ) { $query->set( 'orderby', 'title' ); $query->set( 'order', 'ASC' ); } } add_action( 'pre_get_posts', 'foo_modify_query_order' );Any help is appreciated, as always. Thank you!
November 3, 2022 at 2:40 pm #2400667Ying
StaffCustomer SupportHi Jason,
Can you link us to the archive page?
November 3, 2022 at 3:00 pm #2400686Jason
I added two links – one to the archive page and one to the single product page where the pagination is. Thank you
November 3, 2022 at 5:29 pm #2400764Fernando Customer Support
Hi Jason,
May we know what exactly is occurring with the pagination? I tried testing the pagination from my end, and it seems to be working as expected.
Let us know.
November 3, 2022 at 6:23 pm #2400790Jason
Hi Fernando. It appears to be working with some products, but it’s not. I included a single product page that starts with W and the “next” pagination tab goes to an H (archive page is alphabetical, but single post pagination is off). Thanks for looking!
November 3, 2022 at 7:09 pm #2400805Fernando Customer Support
I see. That code you have only works for archive pages. The single post pagination is a bit more complicated.
It uses WordPress function:
previous_post_linkandnext_post_linkReferences:
https://developer.wordpress.org/reference/functions/previous_post_link/
https://developer.wordpress.org/reference/functions/next_post_link/These two functions retrieve posts ordered by date. It’s not possible in these functions to change the order. You would need to alter the Query of the posts inherently. Altering WordPress core would be out of our scope. See: https://generatepress.com/what-support-includes/
I saw this thread however which might help though: https://stackoverflow.com/questions/9925035/wordpress-previous-post-link-next-post-link-by-alphabetical-order
November 3, 2022 at 8:33 pm #2400843Jason
I understand, and thank you for the references, Fernando! I appreciate the time. I’ll look into it and see if I can hack something together.
November 3, 2022 at 8:42 pm #2400852Fernando Customer Support
You’re welcome Jason!
November 3, 2022 at 9:48 pm #2400883Jason
Fernando – That lead to stack overflow was money! I added a snippet and a custom hook and I have officially modified my single post navigation! Thank you again!!
November 3, 2022 at 10:43 pm #2400922Fernando Customer Support
You’re welcome Jason! Glad to be of assistance!
-
AuthorPosts
- You must be logged in to reply to this topic.