Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$6
How to allow sort for custom field value for ASC and DESC?
I am using custom field query plugin. I want to create a sort option in the front end of wp to allow user to sort price from lowest to highest or highest to lowest.
I register the function in my custom function of headwaytheme.
add_action('init', 'register_From_Price');
function register_From_Price(){
register_custom_queryable_field("From_Price", array("dataType"=>"numeric","order"=>"DESC"));
}By changing the default to 'ASC'. Then I place the following code:
<span class="lowest"><a href="<?php echo add_query_arg('order_by','From_Price', 'order'=>'ASC');?>">Lowest</a>
</span>
<span class="highest"><a href="<?php echo add_query_arg( 'order_by', 'From_Price' ); ?>">Highest</a>
</span>
<span class="clearfilter"><a href="<?php echo add_query_arg( 'order_by', ' ' ); ?>">Clear Filter</a>
</span>It is working for the 'highest' option, mainly I think is default. But for the lowest, it is not working. And If I click on the 'lowest' option, since it is not working, the url will still stay unchanged even though I added a option call 'clear filter', the url will not change back though the post do reorder back to the original state.
Let me know of any suggestion or solution.
This question has been answered.
wan | 10/29/11 at 12:52pm
Edit
The experts have suggested, on average, a prize of $23 for this question.
(2) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
10/29/11
1:13pmLuis Abarca says:
Check this answer too http://wpquestions.com/question/show/id/2204, Julian Lannigan create a plugin for a similar problem.Previous versions of this answer: 10/29/11 at 1:12pm | 10/29/11 at 1:13pm
- 10/29/11 2:00pm
wan says:I have read that, but it does not help me. My register function work well, its the link on the front end that is not working.
echo add_query_arg('order_by','From_Price') just output the default on whatever I have registered.
echo add_query_arg('order_by','From_Price', 'order'=>'ASC') is not working and the sort never take place. Url also unchanged.
It needs to be order_by, orderby do not work.
- 10/31/11 6:13pm
Luis Abarca says:try add_query_arg in this way:
<span class="lowest"><a href="<?php echo add_query_arg( array('order_by' => 'From_Price', 'order' => 'ASC') ) ?>">Lowest</a>
</span>
<span class="highest"><a href="<?php echo add_query_arg( array('order_by' => 'From_Price') ) ?>">Highest</a>
</span>
<span class="clearfilter"><a href="<?php echo add_query_arg( array('order_by' => ' ') ) ?>">Clear Filter</a>
</span>
- 10/29/11 2:00pm
-

Last edited:
10/31/11
9:24pmGabriel Reguly says:Hi wan,
Looks like Luis got the correct answer for the front end, but your code needs another fix, so instead of
register_custom_queryable_field("From_Price", array("dataType"=>"numeric","order"=>"DESC"));
please try
register_custom_queryable_field("From_Price", array("dataType"=>"numeric") );
Regards,
Gabriel
Previous versions of this answer: 10/31/11 at 9:24pm
This question has expired.
Gabriel Reguly voted on this question.
Current status of this question: Completed
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
