FacetWP group listings by custom field [closed]

I finally fixed it: <?php $state_posts = array(); while ($query->have_posts()) { $query->the_post(); $state = get_post_meta(get_the_ID(), ‘state’, true); $state_posts[$state][] = $post; } wp_reset_query(); foreach ($state_posts as $state_post => $state_title) { ?> <h1 class=”state-name”><?php echo esc_html($state_post); ?></h1> <?php foreach ($state_title as $listing => $single_listing) { setup_postdata($single_listing); $post_id = $single_listing->ID; $title = get_the_title($post_id); $distance = facetwp_get_distance($post_id); $distance = … Read more

Remove query string specific key value

[EDIT] This should work the way you wanted it to: $marca = get_query_var(‘marca’); $marca_arg = isset($marca) && is_array($marca) ? $marca : []; $url_base = remove_query_arg( ‘marca’ ); $n = count( $marca_arg ); foreach ($marcas_terms as $marca_term) { $selected = in_array( $marca_term->slug, $marca_arg ); if ( $selected ) { $marca_arg2 = array_diff( $marca_arg, [ $marca_term->slug ] … Read more

Query different number of posts with different formats in one go

This isn’t possible in one query. You can’t set posts per page for individual taxonomy queries. You can either query 12 status or aside posts together: array( ‘posts_per_page’ => 12, ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => array( ‘post-format-status’, ‘post-format-aside’ ), ), ), ) Or perform separate queries with get_posts() … Read more

Search Posts with Custom Fields as query

There are few ways to solve this problem… 1. Don’t bother and use Relevansi (or some other similar plugin) You can often hear that using many plugins is a bad thing. It’s not entirely true. It’s bad only if these plugins have big impact on use of resources. In this case, Relevansi won’t cause such … Read more

How can I remove posts of a certain category from homepage after a specified time period?

This looks straightforward, but unfortunately isn’t, because wp_query doesn’t allow you to exclude posts on basis of multiple arguments (in this case category and date). You can select on basis of multiple arguments, but not exclude. So, to do what you want, you must in some way bundle your two arguments into one. Conceptually, you … Read more

WP_Query ajax loader detect end of posts

Page template: <div class=”entry-content”> <?php $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => ‘2’, ‘paged’ => 1, ); $my_posts = new WP_Query($args); if ($my_posts->have_posts()) : ?> <div class=”my-posts”> <?php while ($my_posts->have_posts()) : $my_posts->the_post(); ?> <h2><?php the_title(); ?></h2> <?php the_excerpt(); ?> <?php endwhile; ?> </div> <?php endif; ?> <div class=”loadmore”>Load More…</div> </div> Ajax … Read more