简体   繁体   中英

wordpress custom loop ascending descending posts by custom field

I am developing wordpress site that is depend upon price so i add custom filed named 'price'

<?php 
while ( have_posts() ) : the_post();
echo  $price = get_post_meta($post->ID, 'price', TRUE);
endwhile;
 ?>

it is basic loop to show out price of all post. requirement : can anybody modify above so its shows post according ascending or descending order like every price site

I do not know if I did well, but that's what you need?

 <?php query_posts(array('posts_per_page'=>20,'meta_key' => 'price','orderby' => 'meta_value_num','order' => 'ASC',))?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

 echo  $price = get_post_meta($post->ID, 'price', TRUE);

 <?php endwhile; endif; ?>

Good Luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM