Note that there are some explanatory texts on larger screens.

plurals
  1. POWordpress search order results
    primarykey
    data
    text
    <p>Don't know what I'm doing wrong here.</p> <p>I have a working search function for a property search which I can use to search custom fields. I want to order the search results by price asc and desc using a dropdown filter at the top of the search results.</p> <p>I have a search.php into which I have placed this code:</p> <pre><code> &lt;?php include (TEMPLATEPATH . '/search-query.php'); ?&gt; &lt;form name="formorder" method="post"&gt; &lt;select name="resultsorder" onChange="formorder.submit();"&gt; &lt;option&gt;Order Results By&lt;/option&gt; &lt;option value="Price High-Low" &lt;?php echo ($resultsorder == 'Price High-Low')? 'selected="selected"':''; ?&gt;&gt;Price Low-High&lt;/option&gt; &lt;option value="Price High-Low" &lt;?php echo ($resultsorder == 'Price High-Low')? 'selected="selected"':''; ?&gt;&gt;Price High-Low&lt;/option&gt; &lt;option value="a-z" &lt;?php echo ($resultsorder == 'a-z')? 'selected="selected"':''; ?&gt;&gt;a-z&lt;/option&gt; &lt;/select&gt; &lt;/form&gt; And I have a search-query.php containing this code: &lt;?php if($resultsorder) { //get value from order dropdown on search results page $resultsorder = $resultsorder; } else { $resultsorder = get_option('wp_searchorder');} switch ($resultsorder) { case "Price High-Low": $metakey = 'price'; $order = 'DESC'; $orderby = 'meta_value_num'; break; case "Price Low-High": $metakey = 'price'; $order = 'ASC'; $orderby = 'meta_value_num'; break; case "a-z": $metakey = 'address'; $order = 'ASC'; $orderby = 'meta_value'; break;} if (!empty($_ids) &amp;&amp; !$alllistings) { $wpq = array ('post_type' =&gt; 'listing', 'meta_key' =&gt; $metakey, 'orderby' =&gt; $orderby, 'order' =&gt; $order, 'post__in' =&gt; $_ids, 'post_status' =&gt; 'publish', 'paged' =&gt; $paged, 'posts_per_page' =&gt; 9999 ); } elseif (empty($_ids) &amp;&amp; !$alllistings) { // $_ids array is empty because search got no results // $_ids array will be empty if page is an "All Listings" page. Don't run this code if is All Listings because All Listings will show all listings. This code will display "no results found" $wpq = array ('post_type' =&gt;'listing', 'meta_key' =&gt; $metakey, 'orderby' =&gt; $orderby, 'order' =&gt; $order, 'post__in' =&gt; array('0'),'post_status' =&gt; 'publish', 'paged' =&gt; $paged, 'posts_per_page' =&gt; 9999); } elseif ($alllistings) { // This is an All Listings page, so show all results $wpq = array ('post_type' =&gt;'listing', 'paged' =&gt; $paged, 'meta_key' =&gt; $metakey, 'orderby' =&gt; $orderby, 'order' =&gt; $order, 'post_status' =&gt; 'publish', 'posts_per_page' =&gt; 9999); } $listing = new WP_Query($wpq);?&gt; </code></pre> <p>Not sure what I'm doing wrong.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload