I'm trying to list advertisers in 3 categories (custom taxonomy "ad_category") as basic, casual and premium. As default query one page contains 10 results but it should be in order to display premium advertisers at top then casual and basic advertisers at last.
Ex: If I'm having a total of 30 premium and casual ads, the basic ads starts from page 4.
My Codes are:
loop-suppliers-basic.php
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$title = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy') );
$args = array(
'post_type' => 'suppliers',
'tax_query' => array(
array(
'taxonomy' => 'ad_category',
'field' => 'slug',
'terms' => array('basic_advertiser'),
),
array(
'taxonomy' => 'supplier_categories',
'field' => 'slug',
'terms' => $title->slug,
),
),
'paged' => $paged,
'orderby' => 'rand'
);
$the_query = new WP_Query( $args ); ?>
<?php if ($the_query->have_posts()) : while($the_query->have_posts()) : $the_query->the_post(); ?>
////////// Loop goes here /////////
<?php endwhile; endif; ?>
taxonomy-supplier_categories.php
<?php get_template_part('loop-suppliers-premium'); ?>
<?php get_template_part('loop-suppliers-casual'); ?>
<?php get_template_part('loop-suppliers-basic'); ?>
<?php get_template_part('pagination'); ?>
Pagination function
function wp_pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
));
}
This does display in order I want but the pagination goes wrong. Tried using methods like **rewind_posts();*but didn't work.
posts_per_page
value? you have 3 separate queries, you will have a number of results up to 3 times whateverposts_per_page
is. also note that you can't randomize order this way with pagination, you will get a random selection on each page with no relationship to the random selection on all the other pages, meaning you will have repeats.posts_per_page
value is 10. Yes, I get your point. Ignore theorderby
. Is there any method to achieve this without having 3 separate queries in 3 files?posts_per_page
to the$args
parameter of each of the 3 separate queries? E.g. if you want 6 posts/ads displayed per page, you'd add'posts_per_page' => 6
to the$args