WordPress meta query: Get lowest or highest number value?

function lowest_price(){

global $wp_query;

$args = array(
  'post_type' => array("automjete", "elektronike", "vendbanime", "sport-rekreacion", "kafshe", "telefona", "shtepi-kopsht", "veshje-bukurie", "biznes-sherbime"),  
  'orderby' =>  'meta_value', // meta_value_num for value
  'order' => 'ASC', // or DSC for low/high
  'posts_per_page' => 1,
  'meta_query'        => array(
            array(
                'key' => 'meta-box-price',
                'type' => 'UNSIGNED'
            )
        )
);

$wp_query = new WP_Query( $args );

if ( $wp_query->have_posts() ) {
  while ( $wp_query->have_posts() ) {
    $wp_query->the_post(); 

     return get_post_meta(get_the_ID(), "meta-box-price", true);

  }
}
	
} 
function highest_price(){

global $wp_query;

$args = array(
  'post_type' => array("automjete", "elektronike", "vendbanime", "sport-rekreacion", "kafshe", "telefona", "shtepi-kopsht", "veshje-bukurie", "biznes-sherbime"),  
  'orderby' =>  'meta_value', // meta_value_num for value
  'order' => 'DSC', // or DSC for low/high
  'posts_per_page' => 1,
  'meta_query'        => array(
            array(
                'key' => 'meta-box-price',
                'type' => 'UNSIGNED'
            )
        )
);

$wp_query = new WP_Query( $args );

if ( $wp_query->have_posts() ) {
  while ( $wp_query->have_posts() ) {
    $wp_query->the_post(); 

     return get_post_meta(get_the_ID(), "meta-box-price", true);

  }
}
	
} 

Share this post:

Share on facebook
Share on twitter
Share on linkedin
Share on email
Amitpal Singh
Amitpal Singh
Freelance website and application developer. Working from Sangrur Punjab in India.
Follow Amitpal on:

Register

Create your account and post ad