Forums Forums Search & Filter Pro Having trouble getting pagination AND filtering to work.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Anonymous
    #205546

    Hello. New user here.

    I’m having trouble getting pagination AND filtering to work. It’s one or the other, not both.

    I’m using filtering on a Custom Post Type Archive in a custom theme. I tried to adapt my code to work like the results.php file, but it kept failing on the pagenavi args.

    wp_pagenavi( array( 'query' => $the_query ) ); <– this just kept killing the page.

    So.. I tried to simplify the query so it was a little more basic, but no matter what I pass to the ‘query’ arg in wp_pagenavi, nothing works.

    The problem here, is I need to alphabetize my unfiltered results by a custom_meta. I’ve tried to search through support and try a few things, but I’m not getting it to work.

    This is the code I’m pulling into my archive-thoughtleaders.php via get_template_party :

    
    <?php
    	$posts = get_posts(array(
    		'post_type'			=> 'thoughtleaders',
    		'posts_per_page'	=> 10,
    		'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
    		'meta_key'			=> 'last_name',
    		'orderby'			=> 'meta_value',
    		'order'				=> 'ASC'
    	));
    ?>
    <?php //$the_query = new WP_Query( $posts ); // the results.php file didn't have this.. BUT without this, the $the_query from results.php sample throws an error on pagenavi. But docs say don't use custom loops. this essentially breaks the filtering but makes pagination work. '?>
    
    <?php if ( have_posts() ) : ?>
    	
    	<?php if (function_exists('wp_pagenavi')) { ?>
    		<div class="pagination">
    			<?php wp_pagenavi( array( 'query' => $the_query ) ); ?>
    			<?php //wp_pagenavi(); ?>
    		</div>
    	<?php } ?>
    	
    	<div class="leaderDirectory">
    	
    	<?php while ( have_posts() ) : the_post(); ?>
    		
    		<div class="leaderEntry">
    			<a  href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    				<?php if ( has_post_thumbnail() ) { ?>
    					<?php the_post_thumbnail('headshot-large');?>
    				<?php } else { ?>
    					<img src="https://via.placeholder.com/680x680" alt="" />
    				<?php } ?>
    				<div class="leaderEntryMeta">
    					<h4><?php the_title(); ?></h4>
    					<?php //the_excerpt(); ?>
    					<p><?php echo wp_trim_words( get_the_excerpt(), 20, '&hellip;' ); ?></p>
    					<p class="readMore">read more</p>
    				</div>
    			</a>
    		</div>
    		
    	<?php endwhile; ?>
    	
    	</div>
    	
    	<?php if (function_exists('wp_pagenavi')) { ?>
    		<div class="pagination">
    			<?php wp_pagenavi( array( 'query' => $the_query ) ); ?>
    			<?php //wp_pagenavi(); ?>
    		</div>
    	<?php } ?>
    
    <?php else : ?>
    	 <p>No Results Found</p>
    <?php endif; ?>
    Trevor
    #205557
    This reply has been marked as private.
    Anonymous
    #205565

    Ok.. we’ve got that sorted, but there was some issues persisting.

    With AJAX enabled, sometimes a form submission would lead to no results (when it should.). With AJAX off, it seems to work better.

    BUT

    when using the text field to search for a word that is in the title of one of the posts, it doesn’t return expected results. It either comes up with nothing, or a totally different post.

    Trevor
    #205595
    This reply has been marked as private.
Viewing 4 posts - 1 through 4 (of 4 total)