I have a wordpress loop that pulls all of my data from a table…
$query = new WP_Query( $args );// The Loop
$i = 0; $i = -1;
while ( $query->have_posts() )
{
$i++;
$query->the_post();
if ( $keys = get_post_custom_keys() )
{
echo "<div class='clearfix card-prod ".($i==0?'first':'')."'><div class='top-dets'><span class='card-title'>";
echo the_title();
echo "</span>";
$order_value = get_post_custom_values('order');
foreach ( $order_value as $key => $value ) {
echo $value ;}
// Network query
$network_value = get_post_custom_values('srchnetwork');
foreach ( $network_value as $key => $value ) {
echo '<span class="srch-val-">'. $value . '</span>'; }
// Pricing Query
$pricing_value = get_post_custom_values('srchpricing');
foreach ( $pricing_value as $key => $value ) {
echo '<span class="srch-val-1">'. $value . '</span>'; }
// Setup Query
$setup_value = get_post_custom_values('srchsetupfee');
foreach ( $setup_value as $key => $value ) {
echo '<span class="srch-val-2">'. $value . '</span>'; }
// Services Query
$services_value = get_post_custom_values('srchservices');
foreach ( $services_value as $key => $value ) {
echo '<span class="srch-val-3">'. $value . '</span></div>'; }
// Big Card Query
$bigcard_value = get_post_custom_values('bigcard');
foreach ( $bigcard_value as $key => $value ) {
echo '<img src="wp-content/themes/cafc/images/cards/'. $value . '" />'; }
echo '<img src="wp-content/themes/cafc/images/top-choice.jpg" alt="Top Choice" class="topchoice">';
echo the_excerpt()."</div>";
}
}
my variable $order_value pulls a numberic value from the database in the order they should be listed in…
Is it possible to sort my results based on this value?
$order_value = get_post_custom_values('order');
foreach ( $order_value as $key => $value ) {
echo $value ;}
Taking @David Nguyen advice I pasted in the code to this…
$args = array('orderby' => 'meta_value_num', 'meta_key' => 'order', 'order' => 'DESC',
'meta_query' => array(
array(
'key' => $customkey,
'value' => $customvalue,
'compare' => '='
),
array(
'key' => $customkey1,
'value' => $customvalue1,
'compare' => '='
)
)
);
Only it doesnt seem to work…
Add this to your args in WP_Query:
'orderby' => 'meta_value_num', 'meta_key' => 'order', 'order' => 'DESC'
http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters