“How to” with FacetWP

As you’ve gone for Adding an Advanced Filtering System with FacetWP, then you probably figured out how to play with it, adding new facets and more. With that being said, here are a couple of examples that can be used under Settings → FacetWP → Templates in the Listings template:

How to sort them alphabetically:

<?php
return array(
  "post_type" => "job_listing",
  "post_status" => "publish",
  "orderby" => "title",
  "order" => "ASC",
  "posts_per_page" => 50
);
<?php
return array(
 "post_type" => "job_listing",
 "post_status" => "publish",
 'meta_key'   => '_featured',
 "orderby" => array( 'meta_value_num' => 'DESC', 'title' => 'ASC' ),
 "posts_per_page" => 50,
);

How to show different number of listings per page depending on screen size:

<?php
if ( wp_is_mobile() ) {
  return array(
      'post_type' => 'any',
      'post_status' => 'publish',
      'posts_per_page' => 10,
  );
}else{
  return array(
      'post_type' => 'any',
      'post_status' => 'publish',
      'posts_per_page' => 16,
  );
}

Of course, you can have more sorting methods by using FaceWP’s Query builder or by checking out the WordPress Query Arguments.

Updated on July 16, 2021

Can't find what you’re looking for? Ask a human.

We're a small team of real people providing real help. Send us an email at hello@pixelgrade.com and we will give you a helping hand.