Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How to exclude posts by meta key value in the_post_navigation next prev links?

In your code this in the condition where you decide when to apply the meta query condition:

if($query->is_main_query()) {

Therefore if the conditions inside there are working sometimes and not others, it means that condition is true when it’s working and not when it’s not.

The solution to this is dependent on all the code running on your site, but first I’d suggest validating this theory by changing this line to the below. Do this on your development environment or temporarily in production if you have to

if(true) {

This means those meta conditions will get applied to every query. Obviously you don’t want that, but if your other paginated pages start working as you want that will confirm this is the problem.

If it is the problem, you just need to find another condition that suits what you need better than is_main_query. For example is_home could be what you’re looking for

If that’s not the problem, then something else more complicated is happening on your other paginated pages that’s messing with your queries, or using a different method that’s ignoring these parameters.

Related Posts:

  1. Can the Next/Prev Post links be ordered by menu order or by a meta key?
  2. How can I limit the length of the previous/next posts in my WordPress Theme?
  3. Problem excluding category from get_next_post
  4. specify meta_key / meta_value condition for prev_post_link and next_post_link
  5. connect last post with first post
  6. Is it possible to nest get_previous_post()?
  7. previous/next_post_link in the same sub-category?
  8. get_adjacent_post – in same term or category not working
  9. next_post_link / previous_post_link not working with WP_Query
  10. Can’t get the previous and next posts permalink
  11. Next/Previous links doesn’t work in the same category
  12. How do I display a greyed out next_post_link when there is no next post
  13. Include “Scheduled” (“Future”) Posts in WordPress Post Navigation ( previous_post_link, next_post_link ) for a Specific Custom Post Type
  14. Next/Previous Product with custom order by price & products inside the product category [closed]
  15. How to get next post link of child custom post type from parent post and get next post link of parent post from the last child post?
  16. Prev/Next Navigation on Single Post Disappeared for Custom Post Type
  17. Change URL of previous posts and next posts link in WordPress
  18. Dynamic next and previous post links
  19. Post in multiple categories do not include in previous / next post if one category in excluded
  20. Previous / next posts using featured image thumbnail as links
  21. How do I retrieve the slug of the current page?
  22. Most efficient way to get posts with postmeta
  23. Get posts by meta value
  24. Explanation of update_post_(meta/term)_cache
  25. How to extract data from a post meta serialized array?
  26. How to save an array with one metakey in postmeta?
  27. WordPress is stripping escape backslashes from JSON strings in post_meta
  28. How can I get the post ID from a WP_Query loop?
  29. Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
  30. is it possible to get next_post_link
  31. How to update_post_meta value as array
  32. Adding meta tag without plugin
  33. What’s the point of get_post_meta’s $single param?
  34. Get Previous & Next posts by Post ID
  35. What is the different between an attachment in wp_posts and an attachment in wp_postmeta?
  36. Filter next_post_link() and previous_post_link() by meta_key?
  37. How to edit a post meta data in a Gutenberg Block?
  38. Sanitizing integer input for update_post_meta
  39. post formats – how to switch meta boxes when changing format?
  40. How can I add title attributes to next and previous post link functions?
  41. Execute action after post is saved with all related post_meta records (data)
  42. Lack of composite indexes for meta tables
  43. How to Get Next or Previous Post in a Specific Tag?
  44. Get a single post by a unique meta value
  45. if get_post_meta is empty do something
  46. How we get_post_meta without post id
  47. How get post id from meta value
  48. What is the code to get the download link for a product in WooCommerce?
  49. Safe to delete blank postmeta?
  50. How to get next and previous post links, alphabetically by title, across post types, in a shortcode
  51. advanced custom fields update_field for field type: Taxonomy
  52. get_adjacent_post alternative on a very large db
  53. update_post_meta not saving when value is zero
  54. Content hooks vs User hooks
  55. Meta compare with date (stored as string) not working
  56. Prev/Next child navigation for current page?
  57. How can I get next/ previous post links to order by a filter (by the last word of the title)?
  58. Trying to get custom post meta through Jetpack JSON API [closed]
  59. next and previous post link ordered alphabetically
  60. How to update/insert custom field(post meta) data with wordpress REST API?
  61. Thumbnail (featured image) of next and previous post is not being properly displayed!
  62. Restrict post edit/delete based on user ID and custom field
  63. get_post_meta returning empty string when data shows in the database
  64. publish_post action hook doesn’t give post_meta_data
  65. Remove WordPress.org Meta link
  66. Remove post meta keys
  67. How to access the post meta of a post that has just been published?
  68. Why time functions show invalid time zone when using ‘c’ time format?
  69. How to use next_post_link and previous_post_link on single posts in search results
  70. Why is get_post_meta returning an array when I specify it as single?
  71. Next/Previous Posts Links: Alphabetically and from Same Category
  72. How to update/delete array in post meta value?
  73. How to get all term meta for a taxonomy – getting term_meta for taxonomy
  74. Adding an assisting editor box to Post page
  75. How can I get next post id after current post id for custom post type
  76. Why is previous_post_link and next_post_link working outside of the Loop?
  77. delete unused postmeta
  78. adding custom fields to next and previous post link
  79. Should I sanitize custom post meta if it is going to be escaped later?
  80. Add post meta based on another post meta value before publish post
  81. How do I retrieve multi-dimensional arrays from the wp_postmeta table, & display on a website?
  82. Front-end update_post_meta snippet displays white screen?
  83. Query between two meta values?
  84. Save both current and new version of post meta
  85. Get Advanced Custom Fields values before saving [closed]
  86. Give extra post-meta to RSS feeds
  87. How to get meta value in wp_attachment_metadata
  88. WP REST API “rest_no_route” when trying to update meta
  89. Clean up output added via wp_head()
  90. List posts under meta_value heading
  91. Using previous_post_link and next_post_link to wrap around post sequence
  92. Why am I getting an infinite loop with have_posts?
  93. get_post_meta – get a single value
  94. Disable “previous link” in first post and “next link” in last post
  95. delete value 0 in post meta [closed]
  96. previous / next post with thumbnail
  97. Can I safely delete a record, manually, in the wp postmeta table?
  98. How to store post meta in an array?
  99. What action hook updates post meta?
  100. Can’t translate the post meta data (Date) in another language
Categories post-meta Tags navigation, next-post-link, post-meta, previous-post-link
change the h3 subtitles of the wordpress gallery shortcode
Edit Post Permalink option removed, looking for possible causes

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress