I like to create a page to filter messages by several criteria.
I can work with wp_query and deliver messages quite easily, my problem is that I can not understand (and can not find any answers on the Internet about this, believe me, I looked) how to allow users to do this.
Take this, for example, returning messages in order of price (custom meta value field) from highest to lowest with 33 messages.
<?php $featuredPosts = new WP_Query( array( 'posts_per_page' => 33, 'meta_key'=>'Price', 'orderby' => 'meta_value_num', 'order' => DESC ) ); ?> <?php if ( $featuredPosts->have_posts() ) : ?> <?php while ( $featuredPosts->have_posts() ) : $featuredPosts->the_post(); ?> <article <?php post_class('item-post block'); ?> id="post-<?php the_ID(); ?>"> <h2 class="price-title"><?php the_title(); ?> </h2> </article> <?php endwhile; wp_reset_query(); ?> <?php endif; ?>
Now, even after reading and searching on Google, I will be damned if I can understand how Id implements this at the front end so that users can filter messages.
I mean, I know that you can add URLs in Wordpress to change the order of posts, but in this context I completely lost.
I tried this, but it does not work.
<?php $by_price = esc_url(add_query_arg(array( 'meta_key' => 'price', 'orderby' => 'meta_value_num', 'order' => ASC ))); $by_date = esc_url(add_query_arg(array( 'orderby' => 'date', 'order' => DESC ))); ?> <ul> <li><a href="<?php echo $by_price;?>">Order by price</a></li> <li><a href="<?php echo $by_date;?>">Order by date</a></li> </ul>
What I'm trying to achieve is actually quite simple, let the user select a category, select a price range (guessing that Id is writing something in jQuery to deliver a value to the field), set the number of results that they would like to use.
Ive tried to pick everything up under the sun, which I can think of, without cubes.