Skip to content

emka.web.id

menulis pengetahuan – merekam peradaban

Menu
  • Home
  • Tutorial
  • Search
Menu

How to Fix Pagination on WordPress Custom Loops

Posted on May 6, 2015

So you have added a custom or secondary query to a template file and you get something strange on their pagination? Maybe this solution is solving your problem.

By default, in any given context, WordPress uses the main query to determine pagination. The main query object is stored in the $wp_query global, which is also used to output the main query loop:

[sourcecode]if ( have_posts() ) : while ( have_posts() ) : the_post();[/sourcecode]

When you use a custom query, you create an entirely separate query object:

[sourcecode]$custom_query = new WP_Query( $custom_query_args );[/sourcecode]

And that query is output via an entirely separate loop:

[sourcecode]if ( $custom_query->have_posts() ) :
while ( $custom_query->have_posts() ) :
$custom_query->the_post();
[/sourcecode]

But pagination template tags, including previous_posts_link(), next_posts_link(), posts_nav_link(), and paginate_links(), base their output on the main query object, $wp_query. That main query may or may not be paginated. If the current context is a custom page template, for example, the main $wp_query object will consist of only a single post – that of the ID of the page to which the custom page template is assigned.

If the current context is an archive index of some sort, the main $wp_query may consist of enough posts to cause pagination, which leads to the next part of the problem: for the main $wp_query object, WordPress will pass a paged parameter to the query, based on the paged URL query variable. When the query is fetched, that paged parameter will be used to determine which set of paginated posts to return. If a displayed pagination link is clicked, and the next page loaded, your custom query won’t have any way to know that the pagination has changed.

And your sollution is by passing Correct Paged Parameter to the Custom Query

Assuming that the custom query uses an args array:

[sourcecode]
$custom_query_args = array(
// Custom query parameters go here
);
[/sourcecode]

You will need to pass the correct paged parameter to the array. You can do so by fetching the URL query variable used to determine the current page, via get_query_var():

[sourcecode]
get_query_var( ‘paged’ );
[/sourcecode]

You can then append that paremeter to your custom query args array:

[sourcecode]
$custom_query_args[‘paged’] = get_query_var( ‘paged’ )
? get_query_var( ‘paged’ )
: 1;
[/sourcecode]

If your page is a static front page, be sure to use page instead of paged as a static front page uses page and not paged. This is what you should have for a static front page

[sourcecode]
$custom_query_args[‘paged’] = get_query_var( ‘page’ )
? get_query_var( ‘page’ )
: 1;
[/sourcecode]

Now, when the custom query is feteched, the correct set of paginated posts will be returned.

I hope it solve your  problem buddy đŸ™‚

Terbaru

  • Game Happy Rush Terbukti Membayar atau Cuma Scam Iklan?
  • Cara Nonton Drama Dapat Duit di Free Flick, Tapi Awas Jangan Sampai Tertipu Saldo Jutaan!
  • APK Pinjol Rajindompet Penipu? Ini Review Aslinya
  • Keganggu Iklan Pop-Up Indosat Pas Main Game? Ini Trik Ampuh Matikannya!
  • Belum Tahu? Inilah Cara Upload Reels Instagram Sampai 20 Menit, Konten Jadi Lebih Puas!
  • Apa itu Negara Somaliland? Apa Hubungannya dengan Israel?
  • Apa itu Game TheoTown? Game Simulasi Jadi Diktator
  • Inilah Rekomendasi 4 HP Honor Terbaik – Prosesor Snapdragon Tahun 2026
  • Lagi Nyari HP Gaming Murah? Inilah 4 HP Asus RAM 8 GB yang Recomended
  • Ini Trik Main Game Merge Cats Road Trip Sampai Tarik Saldo ke DANA
  • Mau Jadi Digital Writer Pro? Ini Caranya Buat Portofolio Pakai Blog!
  • Ini Cara Login Banyak Akun FB & IG di Satu HP Tanpa Diblokir!
  • Inilah Cara Mengatasi Verval Siswa Silang Merah di RDM versi Hosting
  • HP Tertinggal? Inilah Caranya Login PDUM Langsung dari Laptop, Lebih Praktis!
  • Inilah Cara Tarik Dana dari APK Drama Rush
  • Inilah Cara Mudah Tarik Uang Kertas Biru di Merge Cats ke DANA dan OVO Tanpa Ribet!
  • Apakah Aplikasi Pinjaman KlikKami Penipu? Ada DC Penagih?
  • Kenapa Tentara Romawi Hanya Pakai Armor Kaki Saja?
  • Inilah Alasan Kenapa Beli Follower IG itu TIDAK AMAN!
  • EPIK! Kisah Mesin Bor Tercanggih Takluk di Proyek Terowongan Zojila Himalaya
  • Bingung Cari Lokasi Seseorang? Cek Cara Melacak Pemilik Nomor HP Tanpa Bayar Ini, Dijamin Akurat!
  • Apa itu Logis? Kenapa Logika Bisa Berbeda-beda?
  • Ini Alasan Kenapa Fitur Bing AI Sedang Trending dan Dicari Banyak Orang
  • Sejarah Kerajaan Champa: Bangsa Yang Hilang Tanpa Perang Besar, Kok Bisa?
  • Gini Caranya Dapat Weekly Diamond Pass Gratis di Event M7 Pesta, Ternyata Nggak Pake Modal!
  • Inilah Trik Rahasia Panen Token dan Skin Gratis di Event Pesta Cuan M7 Mobile Legends!
  • Apakah Apk Pinjaman Cepat Galaxy Pinjol Penipu?
  • Cara Tarik Saldo APK Game Clear Blast
  • Apakah APK Game Clear Blast Penipu? Ini Reviewnya
  • Inilah Perbedaan SEO dan GEO + Tips Konten Disukai Google dan AI!
  • Tailwind’s Revenue Down 80%: Is AI Killing Open Source?
  • Building Open Cloud with Apache CloudStack
  • TOP 1% AI Coding: 5 Practical Techniques to Code Like a Pro
  • Why Your Self-Hosted n8n Instance Might Be a Ticking Time Bomb
  • CES 2026: Real Botics Wants to Be Your Best Friend, but at $95k, Are They Worth the Hype?
  • Inilah Cara Belajar Cepat Model Context Protocol (MCP) Lewat 7 Proyek Open Source Terbaik
  • Inilah Cara Menguasai Tracing dan Evaluasi Aplikasi LLM Menggunakan LangSmith
  • Begini Cara Menggabungkan LLM, RAG, dan AI Agent untuk Membuat Sistem Cerdas
  • Cara Buat Sistem Moderasi Konten Cerdas dengan GPT-OSS-Safeguard
  • Inilah Cara Membuat Aplikasi Web Full-Stack Tanpa Coding dengan Manus 1.5
  • Apa itu CVE-2025-14847? Ini Penjelasan Lengkap MongoBleed
  • Ini Kronologi & Resiko Kebocoran Data WIRED
  • Apa itu Grubhub Crypto Scam? Ini Pengertian dan Kronologi Penipuan yang Catut Nama Grubhub
  • Apa Itu CVE-2025-59374? Mengenal Celah Keamanan ASUS Live Update yang Viral Lagi
  • Apa itu RansomHouse Mario? Ini Pengertian dan Mengenal Versi Baru ‘Mario’ yang Makin Bahaya
Beli Pemotong Rumput dengan Baterai IRONHOOF 588V Mesin Potong Rumput 88V disini https://s.shopee.co.id/70DBGTHtuJ
Beli Morning Star Kursi Gaming/Kantor disini: https://s.shopee.co.id/805iTUOPRV

©2026 emka.web.id | Design: Newspaperly WordPress Theme