Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Last active May 8, 2026 10:02
Show Gist options
  • Select an option

  • Save searchwpgists/b1d87b0b47050b0313b9f5de59aced26 to your computer and use it in GitHub Desktop.

Select an option

Save searchwpgists/b1d87b0b47050b0313b9f5de59aced26 to your computer and use it in GitHub Desktop.
Wpfilters with Custom WP_Query template
<?php
/**
* Template Name: WP Filters — custom query
*
* @package YourTheme
*/
get_header();
?>
<main id="primary" class="site-main">
<div class="section-inner">
<header class="page-header">
<h1 class="entry-title">
<?php esc_html_e( 'Custom query with WPFilters', 'your-textdomain' ); ?>
</h1>
</header>
<div class="wpfilters-wrapper">
<aside
class="wpfilters-sidebar widget-area"
role="complementary"
aria-label="<?php esc_attr_e( 'Filters', 'your-textdomain' ); ?>"
>
<?php
if ( class_exists( '\WPFilters\Renderer' ) ) {
echo \WPFilters\Renderer::render( 1 ); // Search.
echo \WPFilters\Renderer::render( 2 ); // Category.
echo \WPFilters\Renderer::render( 3 ); // Post type.
}
?>
</aside>
<div class="wpfilters-content content-area">
<?php
// Page templates use `page`; archives use `paged`.
$paged = max(
1,
(int) get_query_var( 'paged' ),
(int) get_query_var( 'page' )
);
$args = array(
'post_type' => array( 'post', 'page' ),
'post_status' => 'publish',
'posts_per_page' => 10,
'paged' => $paged,
'orderby' => 'title',
'order' => 'ASC',
'wpfilters' => true,
);
$query = new WP_Query( $args );
?>
<?php if ( $query->have_posts() ) : ?>
<div class="wpfilters-results">
<?php
while ( $query->have_posts() ) :
$query->the_post();
?>
<article
id="post-<?php the_ID(); ?>"
<?php post_class( 'entry' ); ?>
>
<h2 class="entry-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div>
</article>
<?php endwhile; ?>
</div>
<nav
class="wpfilters-pagination navigation pagination"
aria-label="<?php esc_attr_e( 'Posts pagination', 'your-textdomain' ); ?>"
>
<?php
echo paginate_links(
array(
'total' => $query->max_num_pages,
'current' => $paged,
'mid_size' => 2,
'prev_text' => __( 'Previous', 'your-textdomain' ),
'next_text' => __( 'Next', 'your-textdomain' ),
)
);
?>
</nav>
<?php else : ?>
<p class="wpfilters-results">
<?php esc_html_e( 'No posts found.', 'your-textdomain' ); ?>
</p>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</div>
</div>
</div>
</main>
<?php
get_footer();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment